Skip to content

Commit c75c34e

Browse files
refactor: detect java version (#40)
* refactor: detect java version * style: remove format changes * chore: add default if toolchain unset
1 parent 2dbbf8b commit c75c34e

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
build
66

77
.idea
8+
.DS_Store

hypertrace-gradle-docker-java-application-plugin/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
## [0.9.9]
5555

5656
- Fix bug introduced in 0.9.8 preventing startup. Docker laying improvements not yet working, so
57-
currently equivalent to 0.9.4
57+
currently equivalent to 0.9.4

hypertrace-gradle-docker-java-application-plugin/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ default behavior of `com.bmuschko.docker-java-application` for identifying main
1414
An application can define multiple variants which allow specifying different base images to use.
1515

1616
- `javaVersion`
17-
- JavaVersion
17+
- JavaVersion
18+
- Defaults to the toolchain version from the java plugin
1819
- `baseImage`
1920
- String
2021
- Defaults to hypertrace/java:JavaMajorVersion
@@ -121,4 +122,4 @@ Produces a diff of:
121122
+HEALTHCHECK -interval=2s --start-period=15s --timeout=2s CMD wget -qO- http://127.0.0.1:9003/health &> /dev/null || exit 1
122123
-ENV SERVICE_NAME=example-app
123124
+ENV SERVICE_NAME=example-app MY_VAR=foo
124-
```
125+
```

hypertrace-gradle-docker-java-application-plugin/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ plugins {
44
}
55

66
java {
7-
targetCompatibility = JavaVersion.VERSION_1_8
8-
sourceCompatibility = JavaVersion.VERSION_1_8
7+
targetCompatibility = JavaVersion.VERSION_11
8+
sourceCompatibility = JavaVersion.VERSION_11
99
}
1010

1111
gradlePlugin {
@@ -21,4 +21,3 @@ dependencies {
2121
api("com.bmuschko:gradle-docker-plugin:7.4.0")
2222
api(project(":hypertrace-gradle-docker-plugin"))
2323
}
24-

hypertrace-gradle-docker-java-application-plugin/src/main/java/org/hypertrace/gradle/docker/HypertraceDockerJavaApplicationPlugin.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ public void apply(Project target) {
6363
}
6464

6565
private void addApplicationExtension(Project project) {
66-
this.getHypertraceDockerExtension(project)
67-
.getExtensions()
68-
.create(EXTENSION_NAME, HypertraceDockerJavaApplication.class, project.getName());
66+
HypertraceDockerJavaApplication extension =
67+
this.getHypertraceDockerExtension(project)
68+
.getExtensions()
69+
.create(EXTENSION_NAME, HypertraceDockerJavaApplication.class, project.getName());
70+
71+
extension.javaVersion.convention(
72+
getJavaExtension(project).getToolchain().getLanguageVersion().map(JavaVersion::toVersion)
73+
.orElse(JavaVersion.VERSION_11));
6974
}
7075

7176
private void updateDefaultJvmArgs(Project project, HypertraceDockerJavaApplication javaApplication) {
@@ -233,11 +238,14 @@ private Configuration getRuntimeClasspath(Project project) {
233238
}
234239

235240
private SourceSetOutput mainSourceSetOutput(Project project) {
236-
return project.getExtensions()
237-
.getByType(JavaPluginExtension.class)
238-
.getSourceSets()
239-
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
240-
.getOutput();
241+
return getJavaExtension(project)
242+
.getSourceSets()
243+
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
244+
.getOutput();
245+
}
246+
247+
private JavaPluginExtension getJavaExtension(Project project) {
248+
return project.getExtensions().getByType(JavaPluginExtension.class);
241249
}
242250

243251
private Provider<File> provideIfDirectoryExists(Provider<Directory> directoryProvider) {

hypertrace-gradle-docker-plugin/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ plugins {
44
}
55

66
java {
7-
targetCompatibility = JavaVersion.VERSION_1_8
8-
sourceCompatibility = JavaVersion.VERSION_1_8
7+
targetCompatibility = JavaVersion.VERSION_11
8+
sourceCompatibility = JavaVersion.VERSION_11
99
}
1010

1111
gradlePlugin {

hypertrace-gradle-docker-publish-plugin/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ plugins {
44
}
55

66
java {
7-
targetCompatibility = JavaVersion.VERSION_1_8
8-
sourceCompatibility = JavaVersion.VERSION_1_8
7+
targetCompatibility = JavaVersion.VERSION_11
8+
sourceCompatibility = JavaVersion.VERSION_11
99
}
1010

1111
gradlePlugin {

0 commit comments

Comments
 (0)