Skip to content

Commit 294601d

Browse files
committed
Added possibility to configure the path where the java version is read from
1 parent 06fab3a commit 294601d

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ So, assuming the following usage:
6363
id: jve
6464
```
6565
66+
or if you have the java version in another property like the release property:
67+
68+
```yaml
69+
- uses: joshlong/java-version-export-github-action@v17
70+
id: jve
71+
with:
72+
maven-expression: 'maven.compiler.release'
73+
```
74+
6675
You can use the exported environment variable:
6776
6877
```

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: "java-version-export-github-action"
22
description: "Exports the version of Java specified in pom.xml for use in configuring the version of Java to be used in the github action job"
33

4+
inputs:
5+
maven-expression:
6+
description: "The Maven expression to evaluate for the java version"
7+
required: false
8+
default: "maven.compiler.target"
9+
410
runs:
511
using: "node16"
612
main: "dist/index.js"

index.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function cmd(cmd, args, stdoutListener) {
3232
}
3333

3434
try {
35-
3635
const maven = fs.existsSync('pom.xml')
3736
const gradleGroovy = fs.existsSync('build.gradle')
3837
const gradleKotlin = fs.existsSync('build.gradle.kts')
@@ -41,16 +40,16 @@ try {
4140
console.log(gradleGroovy)
4241
console.log(gradleKotlin)
4342

44-
if (maven) { // maven build
43+
if (maven) {
44+
const mavenExpression = core.getInput('maven-expression');
4545
cmd(
4646
"mvn",
4747
[
4848
"help:evaluate",
4949
"-q",
5050
"-DforceStdout",
51-
"-Dexpression=maven.compiler.target",
51+
`-Dexpression=${mavenExpression}`,
5252
],
53-
// ["help:evaluate", "-q", "-DforceStdout", "-Dexpression=java.version"],
5453
(outputBuffer) => {
5554
const output = outputBuffer.toString();
5655
console.log(output);
@@ -64,23 +63,19 @@ try {
6463
});
6564
}
6665
);
67-
} //
68-
else {
66+
} else {
6967
if (gradleGroovy || gradleKotlin) {
7068
cmd("./gradlew", [ ':properties','--property','sourceCompatibility' ], outputBuffer => {
7169
const buff = outputBuffer.toString();
72-
if (buff.indexOf ('sourceCompatibility')!=-1) {
73-
console.log ('sourceCompatibility: ' + buff)
74-
}
75-
else {
76-
console.log ('nope!')
70+
if (buff.indexOf('sourceCompatibility') != -1) {
71+
console.log('sourceCompatibility: ' + buff)
72+
} else {
73+
console.log('nope!')
7774
}
78-
79-
8075
});
8176
}
8277
}
8378
} catch (error) {
8479
core.setFailed(error.message);
85-
}
80+
}
8681

0 commit comments

Comments
 (0)