Skip to content

Commit

Permalink
Introduce deprecation logger to bypass Gradle 8.12 upcoming deprecati…
Browse files Browse the repository at this point in the history
…ons (#414)
  • Loading branch information
rpalcolea authored Dec 12, 2024
1 parent dd2302d commit 3d9d4af
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 95 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
url = "https://plugins.gradle.org/m2/"
}
}
dependencies {
Expand Down Expand Up @@ -90,7 +90,7 @@ dependencies {

compileOnly "com.netflix.nebula:nebula-test:10.+"

testImplementation 'org.ow2.asm:asm-util:5.2'
testImplementation 'org.ow2.asm:asm-util:9.7.1'
testImplementation 'joda-time:joda-time:latest.release'
testImplementation 'com.netflix.nebula:gradle-info-plugin:latest.release'
}
Expand Down
17 changes: 8 additions & 9 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ com.google.guava:guava:19.0=compileClasspath,runtimeClasspath,testCompileClasspa
com.jcraft:jzlib:1.1.2=integTestRuntimeClasspath,testRuntimeClasspath
com.netflix.nebula:gradle-contacts-plugin:7.0.1=integTestRuntimeClasspath,testRuntimeClasspath
com.netflix.nebula:gradle-info-plugin:13.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:2.2.0=compileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-test:10.6.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:2.2.0=integTestRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:2.3.0=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-test:10.6.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.perforce:p4java:2015.2.1365273=integTestRuntimeClasspath,testRuntimeClasspath
commons-lang:commons-lang:2.6=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
dev.gradleplugins:gradle-api:7.6=compileClasspath
Expand All @@ -34,20 +35,18 @@ org.eclipse.jgit:org.eclipse.jgit:5.0.1.201806211838-r=compileClasspath,runtimeC
org.eclipse.sisu:org.eclipse.sisu.inject:0.3.5=compileClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest-core:1.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest:2.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.0.20=shadow
org.jetbrains.kotlin:kotlin-stdlib:2.1.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.1.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath
org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.9.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.9.0=compileClasspath,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.2.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-analysis:9.7.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-commons:9.7.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-tree:5.2=integTestCompileClasspath,integTestRuntimeClasspath
org.ow2.asm:asm-tree:9.7.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-util:5.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm:5.2=integTestCompileClasspath,integTestRuntimeClasspath
org.ow2.asm:asm:9.7.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-tree:9.7.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-util:9.7.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm:9.7.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-core:2.3-groovy-3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-junit4:2.3-groovy-3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
empty=annotationProcessor,compile,integTestAnnotationProcessor,integTestCompile,integTestCompileOnly,integTestRuntime,runtime,testAnnotationProcessor,testCompile,testCompileOnly,testRuntime
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https://services.gradle.org/distributions-snapshots/gradle-8.12-20241210012659+0000-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.VerificationTask
import org.gradle.internal.deprecation.DeprecationLogger

import static com.netflix.nebula.lint.StyledTextService.Styling.*

Expand All @@ -55,22 +56,26 @@ abstract class FixGradleLintTask extends DefaultTask implements VerificationTask

@TaskAction
void lintCorrections() {
def violations = new LintService().lint(project, false).violations
.unique { v1, v2 -> v1.is(v2) ? 0 : 1 }
//TODO: address Invocation of Task.project at execution time has been deprecated.
DeprecationLogger.whileDisabled {
def violations = new LintService().lint(project, false).violations
.unique { v1, v2 -> v1.is(v2) ? 0 : 1 }

(userDefinedListeners.get() + infoBrokerAction + new GradleLintPatchAction(project)).each {
it.lintFinished(violations)
}
(userDefinedListeners.get() + infoBrokerAction + new GradleLintPatchAction(project)).each {
it.lintFinished(violations)
}

def patchFile = new File(project.layout.buildDirectory.asFile.get(), GradleLintPatchAction.PATCH_NAME)
if (patchFile.exists()) {
new ApplyCommand(new NotNecessarilyGitRepository(project.projectDir)).setPatch(patchFile.newInputStream()).call()
}
def patchFile = new File(project.layout.buildDirectory.asFile.get(), GradleLintPatchAction.PATCH_NAME)
if (patchFile.exists()) {
new ApplyCommand(new NotNecessarilyGitRepository(project.projectDir)).setPatch(patchFile.newInputStream()).call()
}

(userDefinedListeners.get() + infoBrokerAction + consoleOutputAction()).each {
it.lintFixesApplied(violations)
(userDefinedListeners.get() + infoBrokerAction + consoleOutputAction()).each {
it.lintFixesApplied(violations)
}
}


}

GradleLintViolationAction consoleOutputAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.VerificationTask
import org.gradle.internal.deprecation.DeprecationLogger
import org.gradle.internal.reflect.Instantiator

import javax.inject.Inject
Expand Down Expand Up @@ -85,29 +86,31 @@ abstract class GradleLintReportTask extends DefaultTask implements VerificationT

@TaskAction
void generateReport() {
if (reports.any { it.required.isPresent() && it.required.get()}) {
def lintService = new LintService()
def results = lintService.lint(project, false)
filterOnlyFixableViolations(results)
def violationCount = results.violations.size()
def textOutput = new StyledTextService(getServices())

textOutput.text('Generated a report containing information about ')
textOutput.withStyle(Bold).text("$violationCount lint violation${violationCount == 1 ? '' : 's'}")
textOutput.println(' in this project')

reports.each {
if(it.required.isPresent() && it.required.get()) {
it.write(new AnalysisContext(ruleSet: lintService.ruleSet(project)), results)
//TODO: address Invocation of Task.project at execution time has been deprecated.
DeprecationLogger.whileDisabled {
if (reports.any { it.required.isPresent() && it.required.get()}) {
def lintService = new LintService()
def results = lintService.lint(project, false)
filterOnlyFixableViolations(results)
def violationCount = results.violations.size()
def textOutput = new StyledTextService(getServices())

textOutput.text('Generated a report containing information about ')
textOutput.withStyle(Bold).text("$violationCount lint violation${violationCount == 1 ? '' : 's'}")
textOutput.println(' in this project')

reports.each {
if(it.required.isPresent() && it.required.get()) {
it.write(new AnalysisContext(ruleSet: lintService.ruleSet(project)), results)
}
}
}

int errors = results.violations.count { Violation v -> v.rule.priority == 1 }
if (errors > 0) {
throw new GradleException("This build contains $errors critical lint violation${errors == 1 ? '' : 's'}")
int errors = results.violations.count { Violation v -> v.rule.priority == 1 }
if (errors > 0) {
throw new GradleException("This build contains $errors critical lint violation${errors == 1 ? '' : 's'}")
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.internal.deprecation.DeprecationLogger

import static com.netflix.nebula.lint.StyledTextService.Styling.*

Expand Down Expand Up @@ -57,12 +58,16 @@ abstract class LintGradleTask extends DefaultTask {

@TaskAction
void lint() {
def violations = new LintService().lint(project, onlyCriticalRules.get()).violations
.unique { v1, v2 -> v1.is(v2) ? 0 : 1 }
//TODO: address Invocation of Task.project at execution time has been deprecated.
DeprecationLogger.whileDisabled {
def violations = new LintService().lint(project, onlyCriticalRules.get()).violations
.unique { v1, v2 -> v1.is(v2) ? 0 : 1 }

(getListeners() + new GradleLintPatchAction(project) + new GradleLintInfoBrokerAction(project) + consoleOutputAction).each {
it.lintFinished(violations)
(getListeners() + new GradleLintPatchAction(project) + new GradleLintInfoBrokerAction(project) + consoleOutputAction).each {
it.lintFinished(violations)
}
}

}

@Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ class GradleLintPluginSpec extends BaseIntegrationTestKitSpec {
@Unroll
def 'lint task does not run for task #taskName'() {
when:
//TODO: remove ignoreDeprecations once https://github.com/gradle/gradle/issues/31691 is addressed
System.setProperty('ignoreDeprecations', 'true')
disableConfigurationCache() // component and model report are not config cache compatible anyway
buildFile << """
plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class GradleLintRuleSpec extends AbstractRuleSpec {
project.buildFile << """
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
maven { url = 'https://plugins.gradle.org/m2/' }
}
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ test.nebula:a:1.2.0\n""")
allprojects {
apply plugin: 'nebula.lint'
repositories {
maven { url '${mavenrepo.absolutePath}' }
maven { url = '${mavenrepo.absolutePath}' }
}
gradleLint.rules = ['bypassed-forces']
}
Expand Down Expand Up @@ -874,7 +874,7 @@ test.nebula:a:1.3.0\n""")
buildFile << """\
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url = "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("com.netflix.nebula:nebula-dependency-recommender:9.0.2") {
Expand Down Expand Up @@ -968,15 +968,15 @@ test.nebula:a:1.3.0\n""")
buildFile << """\
plugins {
id 'java'
id "com.netflix.nebula.resolution-rules" version "10.1.0"
id "com.netflix.nebula.resolution-rules" version "11.4.1"
id 'nebula.lint'
}
dependencies {
resolutionRules files('$rulesJsonFile')
}
repositories {
maven { url '${mavenrepo.absolutePath}' }
maven { url = '${mavenrepo.absolutePath}' }
}
gradleLint.rules = ['bypassed-forces']
""".stripIndent()
Expand All @@ -987,16 +987,16 @@ test.nebula:a:1.3.0\n""")

buildFile << """\
buildscript {
repositories { maven { url "https://plugins.gradle.org/m2/" } }
repositories { maven { url = "https://plugins.gradle.org/m2/" } }
dependencies {
classpath "com.netflix.nebula:gradle-resolution-rules-plugin:10.1.0"
classpath "com.netflix.nebula:gradle-resolution-rules-plugin:11.4.1"
}
}
allprojects {
apply plugin: 'nebula.lint'
apply plugin: 'com.netflix.nebula.resolution-rules'
repositories {
maven { url '${mavenrepo.absolutePath}' }
maven { url = '${mavenrepo.absolutePath}' }
}
gradleLint.rules = ['bypassed-forces']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ class DependencyServiceSpec extends BaseIntegrationTestKitSpec {
[implementation: 'compileClasspath', testImplementation: 'testCompileClasspath'].each { declaredConf, resolvedConf ->
task "\${declaredConf}Unused"(dependsOn: compileTestJava) {
doLast {
new File(projectDir, "\${declaredConf}Unused.txt").text = DependencyService.forProject(project)
.unusedDependencies(resolvedConf, declaredConf)
.join('\\n')
org.gradle.internal.deprecation.DeprecationLogger.whileDisabled {
new File(projectDir, "\${declaredConf}Unused.txt").text = DependencyService.forProject(project)
.unusedDependencies(resolvedConf, declaredConf)
.join('\\n')
}
}
}
Expand Down Expand Up @@ -132,9 +134,11 @@ class DependencyServiceSpec extends BaseIntegrationTestKitSpec {
project.configurations.collect { it.name }.each { conf ->
task "\${conf}Undeclared"(dependsOn: compileTestJava) {
doLast {
new File(projectDir, "\${conf}Undeclared.txt").text = DependencyService.forProject(project)
.undeclaredDependencies(conf)
.join('\\n')
org.gradle.internal.deprecation.DeprecationLogger.whileDisabled {
new File(projectDir, "\${conf}Undeclared.txt").text = DependencyService.forProject(project)
.undeclaredDependencies(conf)
.join('\\n')
}
}
}
}
Expand Down Expand Up @@ -202,13 +206,17 @@ class DependencyServiceSpec extends BaseIntegrationTestKitSpec {
task compileClasspathSourceSetOutput {
doLast {
println('@@' + DependencyService.forProject(project).sourceSetByConf('compileClasspath').java.classesDirectory.get())
org.gradle.internal.deprecation.DeprecationLogger.whileDisabled {
println('@@' + DependencyService.forProject(project).sourceSetByConf('compileClasspath').java.classesDirectory.get())
}
}
}
task integTestSourceSetOutput {
doLast {
println('@@' + DependencyService.forProject(project).sourceSetByConf('integTestCompileClasspath').java.classesDirectory.get())
org.gradle.internal.deprecation.DeprecationLogger.whileDisabled {
println('@@' + DependencyService.forProject(project).sourceSetByConf('integTestCompileClasspath').java.classesDirectory.get())
}
}
}
"""
Expand Down Expand Up @@ -258,10 +266,12 @@ class DependencyServiceSpec extends BaseIntegrationTestKitSpec {
task coreContents {
doLast {
new File(projectDir, "coreContents.txt").text = DependencyService.forProject(project)
.jarContents(configurations.compileClasspath.resolvedConfiguration.firstLevelModuleDependencies[0].module.id.module)
.classes
.join('\\n')
org.gradle.internal.deprecation.DeprecationLogger.whileDisabled {
new File(projectDir, "coreContents.txt").text = DependencyService.forProject(project)
.jarContents(configurations.compileClasspath.resolvedConfiguration.firstLevelModuleDependencies[0].module.id.module)
.classes
.join('\\n')
}
}
}
"""
Expand Down Expand Up @@ -315,9 +325,11 @@ class DependencyServiceSpec extends BaseIntegrationTestKitSpec {
task resolvableAndResolvedConfigurations {
doLast {
new File(projectDir, "resolvableAndResolvedConfigurations.txt").text = DependencyService.forProject(project)
.resolvableAndResolvedConfigurations()
.join('\\n')
org.gradle.internal.deprecation.DeprecationLogger.whileDisabled {
new File(projectDir, "resolvableAndResolvedConfigurations.txt").text = DependencyService.forProject(project)
.resolvableAndResolvedConfigurations()
.join('\\n')
}
}
}
""".stripIndent()
Expand Down
Loading

0 comments on commit 3d9d4af

Please sign in to comment.