Skip to content

Commit

Permalink
Use Gradle Java Toolchains for target compatibility and Test java lau…
Browse files Browse the repository at this point in the history
…ncher configuration
  • Loading branch information
rpalcolea committed Jan 17, 2023
1 parent c240ebc commit 4af54db
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/nebula.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ jobs:
name: Gradle Build without Publish
steps:
- uses: actions/checkout@v1
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '8'
java-package: jdk
- name: Setup jdk
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
java-package: jdk
- uses: actions/cache@v1
id: gradle-cache
with:
Expand All @@ -46,6 +54,8 @@ jobs:
- ${{ runner.os }}-gradlewrapper-
- name: Gradle build
run: ./gradlew --info --stacktrace build
env:
JDK_VERSION_FOR_TESTS: ${{ matrix.java }}
publish:
if: startsWith(github.ref, 'refs/tags/v')
needs: validation
Expand Down
22 changes: 20 additions & 2 deletions src/main/groovy/nebula/plugin/plugin/NebulaPluginPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ import org.gradle.api.Action
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.jvm.toolchain.JavaToolchainSpec
import org.gradle.jvm.toolchain.JvmVendorSpec
import org.gradle.plugin.devel.tasks.ValidatePlugins
import org.gradle.plugins.signing.Sign
import org.gradle.util.GradleVersion
Expand Down Expand Up @@ -72,8 +77,11 @@ class NebulaPluginPlugin implements Plugin<Project> {
group = 'com.netflix.nebula'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
JavaPluginExtension javaPluginExtension = extensions.getByType(JavaPluginExtension)
JavaToolchainSpec toolchainSpec = javaPluginExtension.toolchain
toolchainSpec.languageVersion.convention(JavaLanguageVersion.of(8))
sourceCompatibility = null
targetCompatibility = null

repositories {
maven {
Expand Down Expand Up @@ -105,9 +113,19 @@ class NebulaPluginPlugin implements Plugin<Project> {
}
}

JavaToolchainService javaToolchainService = project.extensions.getByType(JavaToolchainService)
tasks.withType(Test) { task ->
minHeapSize = '32m'
maxHeapSize = '256m'
/*
Allows to override the JDK used to execute the test process
*/
javaLauncher = javaToolchainService.launcherFor {
it.languageVersion.set(JavaLanguageVersion.of(System.getenv("JDK_VERSION_FOR_TESTS")?.toInteger() ?: 8))
}
doFirst {
logger.lifecycle("Executing tests with JDK: ${System.getenv("JDK_VERSION_FOR_TESTS")?.toInteger() ?: 8}")
}
testLogging {
events "PASSED", "FAILED", "SKIPPED"
}
Expand Down

0 comments on commit 4af54db

Please sign in to comment.