Skip to content

Commit

Permalink
feat(java17): conditional compilation to Java 17 bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgogerly committed Nov 30, 2023
1 parent 8bb8d8f commit e4b2724
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions spinnaker-project-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,12 +19,14 @@ import org.gradle.jvm.tasks.Jar
class SpinnakerBaseProjectConventionsPlugin implements Plugin<Project> {
@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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,5 +19,8 @@ class SpinnakerBaseProjectPlugin implements Plugin<Project> {
project.plugins.apply(SpinnakerLicenseReportPlugin)
project.plugins.apply(DependencyCheckPlugin)
project.plugins.apply(SpinnakerCodeStylePlugin)
if (Flags.shouldEnableCrossCompilation(project)) {
project.plugins.apply(JavaCrossCompilePlugin)
}
}
}

0 comments on commit e4b2724

Please sign in to comment.