Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 4b1a3ee61 -> 412c182ee
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/412c182e Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/412c182e Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/412c182e Branch: refs/heads/GROOVY_2_5_X Commit: 412c182ee816080ba9ff90ff730e2d99eacba228 Parents: 4b1a3ee 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:30:45 2018 +0200 ---------------------------------------------------------------------- build.gradle | 5 ++- gradle/assemble.gradle | 38 ++++++++----------- gradle/bad-practices.gradle | 68 ++++++++++++++++++++++++++++++++++ gradle/binarycompatibility.gradle | 12 +++--- gradle/build-scans.gradle | 2 +- 5 files changed, 94 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/412c182e/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 59fc0b4..4ed96fa 100644 --- a/build.gradle +++ b/build.gradle @@ -50,12 +50,12 @@ buildscript { } plugins { - id 'com.gradle.build-scan' version '1.13.4' + id 'com.gradle.build-scan' version '1.16' id 'me.champeau.buildscan-recipes' version '0.2.3' } buildScan { - licenseAgreementUrl = 'https://gradle.com/terms-of-service' + termsOfServiceUrl = 'https://gradle.com/terms-of-service' apply from: 'gradle/build-scans.gradle' } @@ -70,6 +70,7 @@ ext.modules = { } ext.isReleaseVersion = !groovyVersion.toLowerCase().endsWith("snapshot") +apply from: 'gradle/bad-practices.gradle' //apply from: 'gradle/indy.gradle' apply from: 'gradle/publish.gradle' apply plugin: 'javadocHotfix' http://git-wip-us.apache.org/repos/asf/groovy/blob/412c182e/gradle/assemble.gradle ---------------------------------------------------------------------- diff --git a/gradle/assemble.gradle b/gradle/assemble.gradle index 5aa3a0b..0494394 100644 --- a/gradle/assemble.gradle +++ b/gradle/assemble.gradle @@ -267,12 +267,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' @@ -377,15 +377,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/412c182e/gradle/bad-practices.gradle ---------------------------------------------------------------------- diff --git a/gradle/bad-practices.gradle b/gradle/bad-practices.gradle new file mode 100644 index 0000000..78a53b3 --- /dev/null +++ b/gradle/bad-practices.gradle @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Check if dependency resolution is happening at configuration time +def resolvingAllowed = false +int pcount = allprojects.size() +allprojects { p -> + p.afterEvaluate { + resolvingAllowed = --pcount == 0 + } + 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}") + } + } + } + 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/412c182e/gradle/binarycompatibility.gradle ---------------------------------------------------------------------- diff --git a/gradle/binarycompatibility.gradle b/gradle/binarycompatibility.gradle index 45b951d..4d05cd7 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/412c182e/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 {