Skip to content

Commit 4289ae5

Browse files
committed
split the actions to setup(-and-install)-with(maven|gradle)
1 parent 6d6154d commit 4289ae5

4 files changed

Lines changed: 108 additions & 41 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Setup Java, Gradle and install dependencies'
2+
description: 'Setup Java SDK, Gradle, fetch and cache packages dependencies'
3+
4+
inputs:
5+
working-directory:
6+
description: 'The working directory'
7+
default: '.'
8+
java-version:
9+
default: '21'
10+
description: 'Java Version'
11+
distribution:
12+
default: 'corretto'
13+
description: 'Java Distribution'
14+
cache:
15+
default: 'true'
16+
description: 'Enable Gradle configuration and dependency caching.'
17+
18+
outputs:
19+
distribution:
20+
description: 'Distribution of Java that has been installed.'
21+
value: ${{ steps.setup-java.outputs.distribution }}
22+
version:
23+
description: 'Actual version of the java environment that has been installed.'
24+
value: ${{ steps.setup-java.outputs.version }}
25+
path:
26+
description: 'Path to where the java environment has been installed (same as $JAVA_HOME).'
27+
value: ${{ steps.setup-java.outputs.path }}
28+
cache-hit:
29+
description: 'A boolean value to indicate an exact match was found for the primary key.'
30+
value: ${{ steps.cache.outputs.cache-hit }}
31+
32+
runs:
33+
using: "composite"
34+
steps:
35+
- name: Set up JDK
36+
uses: actions/setup-java@v4
37+
id: setup-java
38+
with:
39+
java-version: ${{ inputs.java-version }}
40+
distribution: ${{ inputs.distribution }}
41+
42+
- name: Setup Gradle
43+
uses: gradle/actions/setup-gradle@v4
44+
with:
45+
cache-disabled: ${{ inputs.cache == 'false' }}
46+
cache-read-only: 'false'
47+
48+
- name: Update dependencies
49+
working-directory: ${{ inputs.working-directory }}
50+
run: ./gradlew build --dry-run
51+
shell: bash
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'Setup Java and build tool'
2-
description: 'Setup Java SDK and the build tool'
1+
name: 'Setup Java and install dependencies'
2+
description: 'Setup Java SDK, fetch and cache packages dependencies'
33

44
inputs:
55
working-directory:
@@ -11,15 +11,12 @@ inputs:
1111
distribution:
1212
default: 'corretto'
1313
description: 'Java Distribution'
14-
build-tool:
15-
default: 'Maven'
16-
description: 'The build tool to use. The options `Maven` and `Gradle` are supported'
1714
cache:
1815
default: 'true'
19-
description: 'Enable Maven/Gradle dependency caching.'
16+
description: 'Enable dependency caching.'
2017
cache-name:
2118
default: 'aboutbits-setup-java'
22-
description: 'Maven cache name. Caches with the same name will share their contents. This is not applicable to Gradle as `gradle/actions/setup-gradle` manages caching for us.'
19+
description: 'Cache name. Caches with the same name will share their contents.'
2320

2421
outputs:
2522
distribution:
@@ -48,16 +45,14 @@ runs:
4845
- name: Cache local Maven repository
4946
uses: actions/cache@v4
5047
id: cache
51-
if: ${{ inputs.cache == 'true' && inputs.build-tool == 'Maven' }}
48+
if: ${{ inputs.cache == 'true' }}
5249
with:
5350
path: ~/.m2/repository
5451
key: ${{ inputs.cache-name }}-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
5552
restore-keys: |
5653
${{ inputs.cache-name }}-${{ runner.os }}-maven-
5754
58-
- name: Setup Gradle
59-
uses: gradle/actions/setup-gradle@v4
60-
if: ${{ inputs.build-tool == 'Gradle' }}
61-
with:
62-
cache-disabled: ${{ inputs.cache == 'false' }}
63-
cache-read-only: 'false'
55+
- name: Update Maven dependencies
56+
working-directory: ${{ inputs.working-directory }}
57+
run: ./mvnw --batch-mode --fail-fast dependency:resolve dependency:resolve-plugins
58+
shell: bash

setup-with-gradle/action.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Setup Java and Gradle'
2+
description: 'Setup Java SDK and Gradle'
3+
4+
inputs:
5+
working-directory:
6+
description: 'The working directory'
7+
default: '.'
8+
java-version:
9+
default: '21'
10+
description: 'Java Version'
11+
distribution:
12+
default: 'corretto'
13+
description: 'Java Distribution'
14+
cache:
15+
default: 'true'
16+
description: 'Enable Gradle dependency caching.'
17+
18+
outputs:
19+
distribution:
20+
description: 'Distribution of Java that has been installed.'
21+
value: ${{ steps.setup-java.outputs.distribution }}
22+
version:
23+
description: 'Actual version of the java environment that has been installed.'
24+
value: ${{ steps.setup-java.outputs.version }}
25+
path:
26+
description: 'Path to where the java environment has been installed (same as $JAVA_HOME).'
27+
value: ${{ steps.setup-java.outputs.path }}
28+
29+
runs:
30+
using: "composite"
31+
steps:
32+
- name: Set up JDK
33+
uses: actions/setup-java@v4
34+
id: setup-java
35+
with:
36+
java-version: ${{ inputs.java-version }}
37+
distribution: ${{ inputs.distribution }}
38+
39+
- name: Setup Gradle
40+
uses: gradle/actions/setup-gradle@v4
41+
with:
42+
cache-disabled: ${{ inputs.cache == 'false' }}
43+
cache-read-only: 'false'
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'Setup Java, build tool and install dependencies'
2-
description: 'Setup Java SDK, the build tool, fetch and cache packages dependencies'
1+
name: 'Setup Java'
2+
description: 'Setup Java SDK'
33

44
inputs:
55
working-directory:
@@ -11,15 +11,12 @@ inputs:
1111
distribution:
1212
default: 'corretto'
1313
description: 'Java Distribution'
14-
build-tool:
15-
default: 'Maven'
16-
description: 'The build tool to use. The options `Maven` and `Gradle` are supported'
1714
cache:
1815
default: 'true'
19-
description: 'Enable Maven/Gradle dependency caching.'
16+
description: 'Enable dependency caching.'
2017
cache-name:
2118
default: 'aboutbits-setup-java'
22-
description: 'Maven cache name. Caches with the same name will share their contents. This is not applicable to Gradle as `gradle/actions/setup-gradle` manages caching for us.'
19+
description: 'Cache name. Caches with the same name will share their contents.'
2320

2421
outputs:
2522
distribution:
@@ -48,28 +45,9 @@ runs:
4845
- name: Cache local Maven repository
4946
uses: actions/cache@v4
5047
id: cache
51-
if: ${{ inputs.cache == 'true' && inputs.build-tool == 'Maven' }}
48+
if: ${{ inputs.cache == 'true' }}
5249
with:
5350
path: ~/.m2/repository
5451
key: ${{ inputs.cache-name }}-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
5552
restore-keys: |
5653
${{ inputs.cache-name }}-${{ runner.os }}-maven-
57-
58-
- name: Update Maven dependencies
59-
working-directory: ${{ inputs.working-directory }}
60-
if: ${{ inputs.build-tool == 'Maven' }}
61-
run: ./mvnw --batch-mode --fail-fast dependency:resolve dependency:resolve-plugins
62-
shell: bash
63-
64-
- name: Setup Gradle
65-
uses: gradle/actions/setup-gradle@v4
66-
if: ${{ inputs.build-tool == 'Gradle' }}
67-
with:
68-
cache-disabled: ${{ inputs.cache == 'false' }}
69-
cache-read-only: 'false'
70-
71-
- name: Update project configuration and Gradle dependencies
72-
working-directory: ${{ inputs.working-directory }}
73-
if: ${{ inputs.build-tool == 'Gradle' }}
74-
run: ./gradlew build --dry-run
75-
shell: bash

0 commit comments

Comments
 (0)