diff --git a/spinnaker-project-plugin/build.gradle b/spinnaker-project-plugin/build.gradle index 4dc712ba..0741d01e 100644 --- a/spinnaker-project-plugin/build.gradle +++ b/spinnaker-project-plugin/build.gradle @@ -5,6 +5,7 @@ dependencies { implementation 'org.owasp:dependency-check-gradle:5.1.0' implementation "com.diffplug.spotless:spotless-plugin-gradle:5.17.1" implementation 'org.eclipse.jgit:org.eclipse.jgit:5.4.0.201906121030-r' + implementation 'com.netflix.nebula:gradle-java-cross-compile-plugin:8.0.0' implementation 'com.netflix.nebula:gradle-ospackage-plugin:8.4.1' implementation 'gradle.plugin.com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:2.1.1' implementation platform('com.google.cloud:libraries-bom:26.1.4') diff --git a/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/Flags.groovy b/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/Flags.groovy new file mode 100644 index 00000000..5e1fbdf6 --- /dev/null +++ b/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/Flags.groovy @@ -0,0 +1,26 @@ +package com.netflix.spinnaker.gradle + +import org.gradle.api.Project + +class Flags { + + /** + * Whether or not the {@code targetJava17} property was set. + */ + static boolean targetJava17(Project project) { + return Boolean.valueOf(project.findProperty("targetJava17")?.toString()) + } + + /** + * Whether cross-compilation should be enabled. + * + * Determined by the project property 'enableCrossCompilerPlugin', and + * disabled by default. + * + * @param project the project from which to read the property + * @return whether cross-compilation should be enabled + */ + static boolean shouldEnableCrossCompilation(Project project) { + return Boolean.valueOf(project.findProperty("enableCrossCompilerPlugin")?.toString()) + } +} diff --git a/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectConventionsPlugin.groovy b/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectConventionsPlugin.groovy index ef65c4c2..705fc03e 100644 --- a/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectConventionsPlugin.groovy +++ b/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectConventionsPlugin.groovy @@ -1,6 +1,6 @@ package com.netflix.spinnaker.gradle.baseproject - +import com.netflix.spinnaker.gradle.Flags import groovy.transform.CompileStatic import org.gradle.api.JavaVersion import org.gradle.api.Plugin @@ -19,12 +19,14 @@ import org.gradle.jvm.tasks.Jar class SpinnakerBaseProjectConventionsPlugin implements Plugin { @Override void apply(Project project) { + def javaVersion = Flags.targetJava17(project) ? JavaVersion.VERSION_17 : JavaVersion.VERSION_11 + project.plugins.withType(JavaBasePlugin) { project.plugins.apply(MavenPublishPlugin) project.repositories.mavenCentral() JavaPluginConvention convention = project.convention.getPlugin(JavaPluginConvention) - convention.sourceCompatibility = JavaVersion.VERSION_11 - convention.targetCompatibility = JavaVersion.VERSION_11 + convention.sourceCompatibility = javaVersion + convention.targetCompatibility = javaVersion } project.plugins.withType(JavaLibraryPlugin) { JavaPluginConvention convention = project.convention.getPlugin(JavaPluginConvention) diff --git a/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectPlugin.groovy b/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectPlugin.groovy index 995afd49..020a137a 100644 --- a/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectPlugin.groovy +++ b/spinnaker-project-plugin/src/main/groovy/com/netflix/spinnaker/gradle/baseproject/SpinnakerBaseProjectPlugin.groovy @@ -1,9 +1,11 @@ package com.netflix.spinnaker.gradle.baseproject +import com.netflix.spinnaker.gradle.Flags import com.netflix.spinnaker.gradle.codestyle.SpinnakerCodeStylePlugin import com.netflix.spinnaker.gradle.idea.SpinnakerIdeaConfigPlugin import com.netflix.spinnaker.gradle.idea.SpinnakerNewIdeaProjectPlugin import com.netflix.spinnaker.gradle.license.SpinnakerLicenseReportPlugin +import nebula.plugin.compile.JavaCrossCompilePlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.owasp.dependencycheck.gradle.DependencyCheckPlugin @@ -17,5 +19,8 @@ class SpinnakerBaseProjectPlugin implements Plugin { project.plugins.apply(SpinnakerLicenseReportPlugin) project.plugins.apply(DependencyCheckPlugin) project.plugins.apply(SpinnakerCodeStylePlugin) + if (Flags.shouldEnableCrossCompilation(project)) { + project.plugins.apply(JavaCrossCompilePlugin) + } } }