From e3b4193178abb0f18341f3548d1ad2437b1126cf Mon Sep 17 00:00:00 2001 From: John Burns Date: Wed, 1 Oct 2025 16:41:39 -0500 Subject: [PATCH] compile main classes on java 8 for backward compatibility test against multiple versions of gradle in happy path tests --- .github/workflows/nebula.yml | 2 +- build.gradle | 15 ++++++++--- gradle.lockfile | 25 ++++++++++--------- .../lint/plugin/FixGradleLintTaskSpec.groovy | 13 ++++++++-- .../lint/plugin/GradleLintPluginSpec.groovy | 25 +++++++++++-------- .../netflix/nebula/lint/GradleVersions.java | 5 ++++ 6 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 src/test/java/com/netflix/nebula/lint/GradleVersions.java diff --git a/.github/workflows/nebula.yml b/.github/workflows/nebula.yml index 1ad1808f..a3ff0476 100644 --- a/.github/workflows/nebula.yml +++ b/.github/workflows/nebula.yml @@ -2,7 +2,7 @@ name: Nebula Build on: push: branches: - - '*' + - 'main' tags: - v*.*.* - v*.*.*-rc.* diff --git a/build.gradle b/build.gradle index 4914c6d7..15eb9848 100644 --- a/build.gradle +++ b/build.gradle @@ -88,7 +88,9 @@ dependencies { plugin 'org.eclipse.jdt:core:3.3.0-v_771' // These are because the AbstractRuleSpec test harness is included in src/main - compileOnly "com.netflix.nebula:nebula-test:11.+" + compileOnly("com.netflix.nebula:nebula-test:10.6.2") { + because("last version compiled on java 8") + } compileOnly("org.spockframework:spock-core:2.3-groovy-4.0") compileOnly("junit:junit:4.13.2") compileOnly(gradleTestKit()) @@ -158,7 +160,7 @@ jar.dependsOn shadowJar java { toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(8)) } } @@ -176,6 +178,9 @@ tasks.withType(Test).configureEach { } } } + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + } } // Kotlin compiles first, stubbing Java dependencies, however it can't stub Groovy and we need to call Groovy code from Kotlin. For details see: @@ -188,7 +193,11 @@ tasks.named('compileKotlin') { // which automatically makes it depend of compileGroovy libraries.from(files(sourceSets.main.groovy.classesDirectory)) } - +tasks.named("compileTestGroovy") { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + } +} ['compileClasspath', 'runtimeClasspath', 'testCompileClasspath', 'testRuntimeClasspath'].each { confName -> tasks.register("dependencyReport${confName.capitalize()}", DependencyReportTask) { configurations = [project.configurations.getByName(confName)] as Set diff --git a/gradle.lockfile b/gradle.lockfile index 896567c6..c9626b2e 100644 --- a/gradle.lockfile +++ b/gradle.lockfile @@ -12,14 +12,14 @@ com.netflix.nebula:gradle-contacts-plugin:7.0.1=integTestRuntimeClasspath,testRu com.netflix.nebula:gradle-info-plugin:14.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath com.netflix.nebula:nebula-gradle-interop:2.3.0=integTestRuntimeClasspath com.netflix.nebula:nebula-gradle-interop:3.0.0=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath -com.netflix.nebula:nebula-test:11.0.0=integTestCompileClasspath,integTestRuntimeClasspath -com.netflix.nebula:nebula-test:11.1.5=compileClasspath,testCompileClasspath,testRuntimeClasspath +com.netflix.nebula:nebula-test:10.6.2=compileClasspath +com.netflix.nebula:nebula-test:11.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath com.perforce:p4java:2015.2.1365273=integTestRuntimeClasspath,testRuntimeClasspath commons-lang:commons-lang:2.6=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath javax.inject:javax.inject:1=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath joda-time:joda-time:2.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath junit:junit:4.13.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -net.bytebuddy:byte-buddy:1.15.11=compileClasspath,testCompileClasspath,testRuntimeClasspath +net.bytebuddy:byte-buddy:1.15.11=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath net.java.dev.jna:jna-platform:5.16.0=integTestRuntimeClasspath,testRuntimeClasspath net.java.dev.jna:jna:5.16.0=integTestRuntimeClasspath,testRuntimeClasspath org.apache.commons:commons-lang3:3.8.1=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath @@ -29,7 +29,7 @@ org.apache.maven:maven-builder-support:3.8.3=compileClasspath,runtimeClasspath,s org.apache.maven:maven-model-builder:3.8.3=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.apache.maven:maven-model:3.8.3=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.apiguardian:apiguardian-api:1.1.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.assertj:assertj-core:3.27.3=compileClasspath,testCompileClasspath,testRuntimeClasspath +org.assertj:assertj-core:3.27.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.codehaus.gpars:gpars:1.2.1=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.codehaus.jsr166-mirror:jsr166y:1.7.0=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.codehaus.plexus:plexus-interpolation:1.26=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath @@ -55,21 +55,22 @@ org.hamcrest:hamcrest-core:1.3=compileClasspath,integTestCompileClasspath,integT org.hamcrest:hamcrest:2.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.jetbrains.kotlin:kotlin-stdlib:2.2.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath -org.jspecify:jspecify:1.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-commons:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath -org.junit.platform:junit-platform-commons:1.13.4=compileClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-engine:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath -org.junit.platform:junit-platform-engine:1.13.4=compileClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-launcher:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath -org.junit.platform:junit-platform-launcher:1.13.4=compileClasspath,testCompileClasspath,testRuntimeClasspath +org.jspecify:jspecify:1.0.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-commons:1.13.4=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-commons:1.9.0=compileClasspath +org.junit.platform:junit-platform-engine:1.13.4=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-engine:1.9.0=compileClasspath +org.junit.platform:junit-platform-launcher:1.13.4=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.multiverse:multiverse-core:0.7.0=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath -org.opentest4j:opentest4j:1.3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath +org.opentest4j:opentest4j:1.2.0=compileClasspath +org.opentest4j:opentest4j:1.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm-analysis:9.8=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm-commons:9.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm-tree:9.8=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm-util:9.8=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm:9.8=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.spockframework:spock-core:2.3-groovy-4.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath +org.spockframework:spock-junit4:2.3-groovy-3.0=compileClasspath org.spockframework:spock-junit4:2.3-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath empty=annotationProcessor,compile,integTestAnnotationProcessor,integTestCompile,integTestCompileOnly,integTestRuntime,runtime,testAnnotationProcessor,testCompile,testCompileOnly,testRuntime diff --git a/src/test/groovy/com/netflix/nebula/lint/plugin/FixGradleLintTaskSpec.groovy b/src/test/groovy/com/netflix/nebula/lint/plugin/FixGradleLintTaskSpec.groovy index e7f3fd21..417b588e 100644 --- a/src/test/groovy/com/netflix/nebula/lint/plugin/FixGradleLintTaskSpec.groovy +++ b/src/test/groovy/com/netflix/nebula/lint/plugin/FixGradleLintTaskSpec.groovy @@ -16,10 +16,12 @@ package com.netflix.nebula.lint.plugin import com.netflix.nebula.lint.BaseIntegrationTestKitSpec +import com.netflix.nebula.lint.GradleVersions import com.netflix.nebula.lint.rule.dependency.DependencyParenthesesRule import com.netflix.nebula.lint.rule.dependency.UnusedDependencyRule import spock.lang.Issue import spock.lang.Subject +import spock.lang.Unroll @Subject([UnusedDependencyRule, DependencyParenthesesRule]) class FixGradleLintTaskSpec extends BaseIntegrationTestKitSpec { @@ -49,8 +51,9 @@ class FixGradleLintTaskSpec extends BaseIntegrationTestKitSpec { results.output.count('unfixed dependency-parentheses') == 1 } + @Unroll def 'lint fixes violation in all applied files'() { - when: + setup: buildFile << """ plugins { id 'nebula.lint' @@ -78,11 +81,17 @@ class FixGradleLintTaskSpec extends BaseIntegrationTestKitSpec { writeHelloWorld() - then: + when: + gradleVersion = testGradleVersion def results = runTasks('fixGradleLint') + + then: results.output.count('fixed dependency-parentheses') == 2 dependenciesFile.text.contains('implementation \'com.google.guava:guava:18.0\'') buildFile.text.contains('implementation \'commons-lang:commons-lang:2.6\'') + + where: + testGradleVersion << GradleVersions.ALL } @Issue('#37') diff --git a/src/test/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginSpec.groovy b/src/test/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginSpec.groovy index 2946b2a6..34ba6e69 100644 --- a/src/test/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginSpec.groovy +++ b/src/test/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginSpec.groovy @@ -16,6 +16,7 @@ package com.netflix.nebula.lint.plugin import com.netflix.nebula.lint.BaseIntegrationTestKitSpec +import com.netflix.nebula.lint.GradleVersions import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.TaskOutcome import spock.lang.Issue @@ -23,8 +24,9 @@ import spock.lang.Unroll class GradleLintPluginSpec extends BaseIntegrationTestKitSpec { + @Unroll def 'run multiple rules on a single module project'() { - when: + setup: buildFile << """ plugins { id 'nebula.lint' @@ -33,26 +35,27 @@ class GradleLintPluginSpec extends BaseIntegrationTestKitSpec { repositories { mavenCentral() } - gradleLint.rules = ['dependency-parentheses', 'dependency-tuple'] + gradleLint.rules = ['dependency-parentheses', 'dependency-tuple', 'unused-dependency'] dependencies { implementation('com.google.guava:guava:18.0') - testImplementation group: 'junit', - name: 'junit', - version: '4.11' + testImplementation "junit:junit:4.11" } """ - then: - def results = runTasks('assemble') - when: - def console = results.output.readLines() + gradleVersion = testGradleVersion + forwardOutput = true + def results = runTasks('assemble') then: - console.findAll { it.startsWith('warning') }.size() == 2 + def console = results.output.readLines() + console.findAll { it.startsWith('warning') }.size() == 3 console.any { it.contains('dependency-parentheses') } - console.any { it.contains('dependency-tuple') } + console.any { it.contains('unused-dependency') } + + where: + testGradleVersion << GradleVersions.ALL } def 'run multiple rules on a single module project with applied file'() { diff --git a/src/test/java/com/netflix/nebula/lint/GradleVersions.java b/src/test/java/com/netflix/nebula/lint/GradleVersions.java new file mode 100644 index 00000000..bd12887d --- /dev/null +++ b/src/test/java/com/netflix/nebula/lint/GradleVersions.java @@ -0,0 +1,5 @@ +package com.netflix.nebula.lint; + +public class GradleVersions { + public static String[] ALL = new String[]{"9.0.0", "9.1.0"}; +}