Repository: groovy Updated Branches: refs/heads/master 257e54588 -> a390fcf41
Fix dependency resolution happening at configuration time And add smarter detection strategy, so that this hopefully doesn't happen again. Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a390fcf4 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a390fcf4 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a390fcf4 Branch: refs/heads/master Commit: a390fcf41b6e0b6a3c794dca7d9b1e03418af179 Parents: 257e545 Author: Cedric Champeau <cchamp...@apache.org> Authored: Fri Oct 12 15:25:24 2018 +0200 Committer: Cedric Champeau <cchamp...@apache.org> Committed: Fri Oct 12 15:25:24 2018 +0200 ---------------------------------------------------------------------- build.gradle | 24 ++++++++++++++-- gradle/assemble.gradle | 46 +++++++++++++----------------- gradle/bad-practices.gradle | 51 ++++++++++++++++++++++++++++------ gradle/binarycompatibility.gradle | 12 ++++---- gradle/build-scans.gradle | 2 +- 5 files changed, 92 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/a390fcf4/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 0fa9d8a..cd37b6a 100644 --- a/build.gradle +++ b/build.gradle @@ -49,14 +49,14 @@ buildscript { } plugins { - id 'com.gradle.build-scan' version '1.15.1' + id 'com.gradle.build-scan' version '1.16' id 'me.champeau.buildscan-recipes' version '0.2.3' id 'com.github.spotbugs' version '1.6.4' id "com.github.ben-manes.versions" version '0.20.0' } buildScan { - licenseAgreementUrl = 'https://gradle.com/terms-of-service' + termsOfServiceUrl = 'https://gradle.com/terms-of-service' apply from: 'gradle/build-scans.gradle' } @@ -463,3 +463,23 @@ licenseReport { //licenseFormat.dependsOn licenseFormatCustom //licenseFormat.dependsOn licenseFormatGradle // + +task preemptiveDownload { + doLast { + configurations.all { + if (canBeResolved) { + // collect all component ids + def componentIds = incoming.resolutionResult.allDependencies.collect { it.selected.id } + + // only keep external components + def externalComponentIds = componentIds.findAll { it instanceof ModuleComponentIdentifier } + + // and now ask Gradle to download them + project.dependencies.createArtifactResolutionQuery() + .forComponents(externalComponentIds) + .withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact) + .execute() + } + } + } +} http://git-wip-us.apache.org/repos/asf/groovy/blob/a390fcf4/gradle/assemble.gradle ---------------------------------------------------------------------- diff --git a/gradle/assemble.gradle b/gradle/assemble.gradle index fa231ac..feb405a 100644 --- a/gradle/assemble.gradle +++ b/gradle/assemble.gradle @@ -213,10 +213,10 @@ allprojects { 'groovy/cli/picocli/OptionAccessor*.class' ] patterns = [ - 'antlr.**' : 'groovyjarjarantlr.@1', // antlr2 - 'org.antlr.**' : 'groovyjarjarantlr4.@1', // antlr4 - 'org.objectweb.**' : 'groovyjarjarasm.@1', - 'picocli.**' : 'groovyjarjarpicocli.@1' + 'antlr.**': 'groovyjarjarantlr.@1', // antlr2 + 'org.antlr.**': 'groovyjarjarantlr4.@1', // antlr4 + 'org.objectweb.**': 'groovyjarjarasm.@1', + 'picocli.**': 'groovyjarjarpicocli.@1' ] excludesPerLibrary = [ '*': ['META-INF/maven/**', 'META-INF/*', 'META-INF/services/javax.annotation.processing.Processor', 'module-info.class'] @@ -265,12 +265,12 @@ allprojects { patterns = [ 'com.googlecode.openbeans.**': 'groovyjarjaropenbeans.@1', 'org.apache.harmony.beans.**': 'groovyjarjarharmonybeans.@1', - 'java.beans.**' : 'groovyjarjaropenbeans.@1' + 'java.beans.**': 'groovyjarjaropenbeans.@1' ] excludesPerLibrary = [ '*': ['META-INF/NOTICE'] ] - excludes = ['META-INF/NOTICE','META-INF/INDEX.LIST'] + excludes = ['META-INF/NOTICE', 'META-INF/INDEX.LIST'] createManifest = false includedResources = [ ("$rootProject.projectDir/notices/${isRoot ? 'NOTICE-GROOIDJARJAR' : 'NOTICE-GROOID'}".toString()): 'META-INF/NOTICE' @@ -376,15 +376,9 @@ ext.distSpec = copySpec { } } } - project(':groovy-jaxb').configurations.jaxb.each { conf -> - into('lib/extras-jaxb') { - from conf - } - } - project(':groovy-jaxb').configurations.jaxbRuntime.each { conf -> - into('lib/extras-jaxb') { - from conf - } + into('lib/extras-jaxb') { + from project(':groovy-jaxb').configurations.jaxb + from project(':groovy-jaxb').configurations.jaxbRuntime } if (!rootProject.hasProperty('skipIndy')) { into('indy') { @@ -553,13 +547,13 @@ task updateLicenses { def jsr223Files = fileTree(licensesDir).include('jsr223-BINZIP-SRC.txt') def licenseHdr = '\n\n------------------------------------------------------------------------\n\n' [ - (licenseBinZipFile) : binzipFiles, - (licenseDocFile) : docFiles, - (licenseJarJarFile) : jarjarFiles, - (licenseSrcFile) : srcFiles, + (licenseBinZipFile): binzipFiles, + (licenseDocFile): docFiles, + (licenseJarJarFile): jarjarFiles, + (licenseSrcFile): srcFiles, (licenseDocGeneratorFile): docgeneratorFiles, - (licenseGroovyDocFile) : groovydocFiles, - (licenseJsr223File) : jsr223Files, + (licenseGroovyDocFile): groovydocFiles, + (licenseJsr223File): jsr223Files, ].each { outFile, inFiles -> file(outFile).withWriter('utf-8') { writer -> writer << ([file(licenseBaseFile)] + inFiles).collect { @@ -608,11 +602,11 @@ task updateNotices { }.sort { it.name } def groovyconsoleFiles = fileTree(noticesDir).include('silkicons-BINZIP-SRC.txt') [ - (noticeBinZipFile) : binzipFiles, - (noticeGrooidFile) : grooidFiles, - (noticeGrooidJarJarFile) : grooidJarjarFiles, - (noticeJarJarFile) : jarjarFiles, - (noticeSrcFile) : srcFiles, + (noticeBinZipFile): binzipFiles, + (noticeGrooidFile): grooidFiles, + (noticeGrooidJarJarFile): grooidJarjarFiles, + (noticeJarJarFile): jarjarFiles, + (noticeSrcFile): srcFiles, (noticeGroovyConsoleFile): groovyconsoleFiles, ].each { outFile, inFiles -> file(outFile).withWriter('utf-8') { writer -> http://git-wip-us.apache.org/repos/asf/groovy/blob/a390fcf4/gradle/bad-practices.gradle ---------------------------------------------------------------------- diff --git a/gradle/bad-practices.gradle b/gradle/bad-practices.gradle index 912675b..3b1c21a 100644 --- a/gradle/bad-practices.gradle +++ b/gradle/bad-practices.gradle @@ -18,16 +18,51 @@ */ // Check if dependency resolution is happening at configuration time +def resolvingAllowed = false +int pcount = allprojects.size() allprojects { p -> - p.ext.resolvingAllowed = false - afterEvaluate { pj -> - pj.ext.resolvingAllowed = true + p.afterEvaluate { + resolvingAllowed = --pcount == 0 } - configurations.all { cnf -> - incoming.beforeResolve { - if (!p.ext.resolvingAllowed) { - throw new IllegalStateException("Configuration $cnf is being resolved at configuration time. This shouldn't be necessary and usually indicates an error in the build script.") + def checkResolution = { cnf -> + cnf.incoming.beforeResolve { + if (!resolvingAllowed) { + def e = new RuntimeException() + List<StackTraceElement> inGradleBuild = e.stackTrace.findAll { it.fileName?.endsWith('.gradle') && !it.fileName.endsWith('bad-practices.gradle') } + def stack = inGradleBuild.collect { + " at ${it.fileName}:${it.lineNumber}" + }.join("\n") + throw new IllegalStateException("Configuration $cnf in project $p is being resolved at configuration time.\nThis shouldn't be necessary and usually indicates an error in the build script.\nSee :\n${stack}") } } } -} \ No newline at end of file + p.configurations.all(checkResolution) + // This will make sure we also capture problems with detached configurations + // However it will only do so with build scripts that use dynamic Groovy + p.configurations.metaClass = new ContainerMetaclassClass(p.configurations.metaClass, checkResolution) +} + +@groovy.transform.CompileStatic +class ContainerMetaclassClass extends DelegatingMetaClass { + Closure configuration + + ContainerMetaclassClass(MetaClass metaClass, Closure configuration) { + super(metaClass) + this.configuration = configuration + } + + Object invokeMethod(Object object, String name, Object[] args) { + maybeConfigure(super.invokeMethod(object, name, args), name) + } + + Object invokeMethod(Object object, String name, Object arg) { + maybeConfigure(super.invokeMethod(object, name, arg), name) + } + + private Object maybeConfigure(Object object, String name) { + if ('detachedConfiguration' == name) { + configuration(object) + } + object + } +} http://git-wip-us.apache.org/repos/asf/groovy/blob/a390fcf4/gradle/binarycompatibility.gradle ---------------------------------------------------------------------- diff --git a/gradle/binarycompatibility.gradle b/gradle/binarycompatibility.gradle index 20a4ace..aa4d1fb 100644 --- a/gradle/binarycompatibility.gradle +++ b/gradle/binarycompatibility.gradle @@ -47,26 +47,26 @@ def compatibilityBaselineVersion = '2.4.15' allprojects { if (project in projectsToCheck) { - File baselineArtifact = null // Use a detached configuration, otherwise the current version's jar will take precedence over the baseline jar. // A necessary hack, the intuitive thing does NOT work: // https://discuss.gradle.org/t/is-the-default-configuration-leaking-into-independent-configurations/2088/6 def saveGroup = project.group + def detachedConf try { project.group = 'virtual_group_for_japicmp' String depModule = "org.codehaus.groovy:${project.name}:${compatibilityBaselineVersion}@jar" String depJar = "${project.name}-${compatibilityBaselineVersion}.jar" - def configuration = configurations.detachedConfiguration( + detachedConf = configurations.detachedConfiguration( dependencies.create(depModule) ) - baselineArtifact = files(configuration.files).filter { - it.name.equals(depJar) - }.singleFile } finally { project.group = saveGroup } task japicmp(type: JapicmpTask, dependsOn: jarjar) { - oldClasspath = files(baselineArtifact) + oldClasspath = files({ + files(detachedConf.files).filter { + it.name.equals(depJar) + }.singleFile}) newArchives = files(jarjar.outputFile) newClasspath = configurations.runtimeClasspath accessModifier = 'protected' http://git-wip-us.apache.org/repos/asf/groovy/blob/a390fcf4/gradle/build-scans.gradle ---------------------------------------------------------------------- diff --git a/gradle/build-scans.gradle b/gradle/build-scans.gradle index 44edca5..8602f9d 100644 --- a/gradle/build-scans.gradle +++ b/gradle/build-scans.gradle @@ -25,7 +25,7 @@ boolean hasRefused = env.GRADLE_SCANS_ACCEPT=='no' || acceptFile.exists() && acc buildScan { if (hasAccepted) { - licenseAgree = 'yes' + termsOfServiceAgree = 'yes' publishAlways() } else if (!hasRefused) { gradle.buildFinished {