Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java17): conditional compilation to Java 17 bytecode #203

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:6.23.2"
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)
}
}
}