diff --git a/build.gradle b/build.gradle index 19feb7076..6d1c618b2 100644 --- a/build.gradle +++ b/build.gradle @@ -62,12 +62,14 @@ repositories { } test { + useJUnitPlatform() + if (System.env.CI == 'true') { testLogging.showStandardStreams = true minHeapSize "1g" maxHeapSize "1g" } - + systemProperty 'java.io.tmpdir', buildDir.absolutePath } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index dc065ccb4..b1e563822 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -16,10 +16,10 @@ dependencies { exclude group: 'org.ow2.asm' } - testImplementation("org.spockframework:spock-core:2.0-M4-groovy-3.0") { + testImplementation('org.spockframework:spock-core:2.0-groovy-3.0') { exclude group: 'org.codehaus.groovy' } - testImplementation "org.spockframework:spock-junit4:2.0-M4-groovy-3.0" + testImplementation 'org.spockframework:spock-junit4:2.0-groovy-3.0' testImplementation 'xmlunit:xmlunit:1.6' testImplementation 'org.apache.commons:commons-lang3:3.12.0' testImplementation 'com.google.guava:guava:30.1.1-jre' diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy index c71282278..323e1d734 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy @@ -1,6 +1,5 @@ package com.github.jengelman.gradle.plugins.shadow -import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification import org.apache.tools.zip.ZipFile import org.gradle.testkit.runner.BuildResult @@ -11,14 +10,6 @@ import java.util.jar.JarFile class ApplicationSpec extends PluginSpecification { - AppendableMavenFileRepository repo - AppendableMavenFileRepository publishingRepo - - def setup() { - repo = repo() - publishingRepo = repo('remote_repo') - } - def 'integration with application plugin'() { given: repo.module('shadow', 'a', '1.0') @@ -124,7 +115,7 @@ class ApplicationSpec extends PluginSpecification { ZipFile zipFile = new ZipFile(zip) println zipFile.entries.collect { it.name } assert zipFile.entries.find { it.name == 'myapp-shadow-1.0/lib/myapp-1.0-all.jar' } - assert zipFile.entries.find { it.name == 'myapp-shadow-1.0/lib/a-1.0.jar'} + assert zipFile.entries.find { it.name == 'myapp-shadow-1.0/lib/a-1.0.jar' } cleanup: zipFile?.close() diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 01f8476fc..7ea155900 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -3,157 +3,18 @@ package com.github.jengelman.gradle.plugins.shadow import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification import groovy.json.JsonSlurper +import groovy.xml.XmlSlurper import org.gradle.api.attributes.Bundling import org.gradle.api.attributes.Usage -import spock.lang.Issue class PublishingSpec extends PluginSpecification { - AppendableMavenFileRepository repo AppendableMavenFileRepository publishingRepo def setup() { - repo = repo() publishingRepo = repo('remote_repo') } - def "publish shadow jar with maven plugin"() { - given: - repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() - repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() - - settingsFile << "rootProject.name = 'maven'" - buildFile << """ - apply plugin: 'maven' - - dependencies { - implementation 'shadow:a:1.0' - shadow 'shadow:b:1.0' - } - - shadowJar { - archiveBaseName = 'maven-all' - archiveClassifier = null - archiveClassifier.convention(null) - } - - uploadShadow { - repositories { - mavenDeployer { - repository(url: "${publishingRepo.uri}") - } - } - } - """.stripIndent() - - when: - runWithDeprecationWarnings('uploadShadow') - - then: 'Check that shadow artifact exists' - File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile - assert publishedFile.exists() - - and: 'Check contents of shadow artifact' - contains(publishedFile, ['a.properties', 'a2.properties']) - - and: 'Check that shadow artifact pom exists and contents' - File pom = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile - assert pom.exists() - - def contents = new XmlSlurper().parse(pom) - assert contents.dependencies.size() == 1 - assert contents.dependencies[0].dependency.size() == 1 - - def dependency = contents.dependencies[0].dependency[0] - assert dependency.groupId.text() == 'shadow' - assert dependency.artifactId.text() == 'b' - assert dependency.version.text() == '1.0' - } - - def "exclude api and implementation dependencies when publishing shadow jar with maven plugin"() { - given: - repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() - repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() - - settingsFile << "rootProject.name = 'maven'" - buildFile << """ - apply plugin: 'java-library' - apply plugin: 'maven' - - dependencies { - api 'shadow:a:1.0' - implementation 'shadow:b:1.0' - } - - uploadShadow { - repositories { - mavenDeployer { - repository(url: "${publishingRepo.uri}") - } - } - } - """.stripIndent() - - when: - runWithDeprecationWarnings('uploadShadow') - - then: 'Check that shadow artifact exists' - File publishedFile = publishingRepo.rootDir.file('shadow/maven/1.0/maven-1.0-all.jar').canonicalFile - assert publishedFile.exists() - - and: 'Check contents of shadow artifact' - contains(publishedFile, ['a.properties', 'a2.properties']) - - and: 'Check that shadow artifact pom exists and contents' - File pom = publishingRepo.rootDir.file('shadow/maven/1.0/maven-1.0.pom').canonicalFile - assert pom.exists() - - def contents = new XmlSlurper().parse(pom) - assert contents.dependencies.size() == 0 - } - - @Issue('SHADOW-347') - def "maven install with application plugin"() { - given: - repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() - repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() - - settingsFile << "rootProject.name = 'maven'" - buildFile << """ - apply plugin: 'maven' - apply plugin: 'application' - - mainClassName = 'my.App' - - dependencies { - implementation 'shadow:a:1.0' - shadow 'shadow:b:1.0' - } - """.stripIndent() - - when: - // The Maven plugin is deprecated - runWithDeprecationWarnings('install') - - then: - noExceptionThrown() - } - def "publish shadow jar with maven-publish plugin"() { given: repo.module('shadow', 'a', '1.0') diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy index 1bc838902..1ac3439d7 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy @@ -184,10 +184,10 @@ class RelocationSpec extends PluginSpecification { def "relocate does not drop dependency resources"() { given: 'Core project with dependency and resource' file('core/build.gradle') << """ - apply plugin: 'java' + apply plugin: 'java-library' repositories { maven { url "${repo.uri}" } } - dependencies { implementation 'junit:junit:3.8.2' } + dependencies { api 'junit:junit:3.8.2' } """.stripIndent() file('core/src/main/resources/TEST') << 'TEST RESOURCE' diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy index deee7b42f..65e150537 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy @@ -86,13 +86,13 @@ class ShadowPluginSpec extends PluginSpecification { assert output.exists() where: - version << ['6.0', '6.1', '6.2'] + version << ['7.0'] } - def 'Error in Gradle versions < 6.0'() { + def 'Error in Gradle versions < 7.0'() { given: GradleRunner versionRunner = GradleRunner.create() - .withGradleVersion('5.5') + .withGradleVersion('6.9') .withArguments('--stacktrace') .withProjectDir(dir.root) .forwardOutput() @@ -796,7 +796,7 @@ class ShadowPluginSpec extends PluginSpecification { buildFile << """ dependencies { - runtime 'shadow:a:1.0' + runtimeOnly 'shadow:a:1.0' shadow 'shadow:b:1.0' } """.stripIndent() @@ -830,25 +830,15 @@ class ShadowPluginSpec extends PluginSpecification { .dependsOn('implementation-dep') .publish() - repo.module('shadow', 'compile', '1.0') - .insertFile('compile.properties', 'compile') - .publish() - - repo.module('shadow', 'runtime', '1.0') - .insertFile('runtime.properties', 'runtime') - .publish() - repo.module('shadow', 'runtimeOnly', '1.0') .insertFile('runtimeOnly.properties', 'runtimeOnly') .publish() - buildFile.text = defaultBuildScript.replace('java', 'java-library') + buildFile.text = getDefaultBuildScript('java-library') buildFile << """ dependencies { api 'shadow:api:1.0' implementation 'shadow:implementation:1.0' - compile 'shadow:compile:1.0' - runtime 'shadow:runtime:1.0' runtimeOnly 'shadow:runtimeOnly:1.0' } """.stripIndent() @@ -857,8 +847,8 @@ class ShadowPluginSpec extends PluginSpecification { versionRunner.withArguments('shadowJar').build() then: - contains(output, ['api.properties', 'implementation.properties', 'compile.properties', - 'runtime.properties', 'runtimeOnly.properties', 'implementation-dep.properties']) + contains(output, ['api.properties', 'implementation.properties', + 'runtimeOnly.properties', 'implementation-dep.properties']) } def "doesn't include compileOnly configuration by default"() { @@ -873,7 +863,7 @@ class ShadowPluginSpec extends PluginSpecification { buildFile << """ dependencies { - runtime 'shadow:a:1.0' + runtimeOnly 'shadow:a:1.0' compileOnly 'shadow:b:1.0' } """.stripIndent() @@ -900,8 +890,8 @@ class ShadowPluginSpec extends PluginSpecification { buildFile << """ dependencies { - runtime 'shadow:a:1.0' - runtime 'shadow:b:1.0' + runtimeOnly 'shadow:a:1.0' + runtimeOnly 'shadow:b:1.0' } """.stripIndent() @@ -917,7 +907,7 @@ class ShadowPluginSpec extends PluginSpecification { given: buildFile << """ - dependencies { compile 'junit:junit:3.8.2' } + dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() when: @@ -988,26 +978,6 @@ class ShadowPluginSpec extends PluginSpecification { } - @Issue('SHADOW-256') - def "allow configuration of non-maven projects with uploads"() { - given: - buildFile << """ - configurations.each { configuration -> - def upload = project.getTasks().getByName(configuration.getUploadTaskName()) - upload.repositories.ivy { - layout 'ivy' - url "\$buildDir/repo" - } - } - """ - - when: - run('shadowJar') - - then: - assert output.exists() - } - @Issue('SHADOW-203') def "support ZipCompression.STORED"() { given: @@ -1103,7 +1073,7 @@ class ShadowPluginSpec extends PluginSpecification { mainClassName = 'myapp.Main' dependencies { - compile 'shadow:a:1.0' + implementation 'shadow:a:1.0' } def generatedResourcesDir = new File(project.buildDir, "generated-resources") diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy index 25243bf52..40f3fdd7c 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy @@ -7,7 +7,7 @@ class RelocationCachingSpec extends AbstractCachingSpec { def 'shadowJar is cached correctly when relocation is added'() { given: buildFile << """ - dependencies { compile 'junit:junit:3.8.2' } + dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() file('src/main/java/server/Server.java') << """ @@ -30,7 +30,7 @@ class RelocationCachingSpec extends AbstractCachingSpec { when: changeConfigurationTo """ - dependencies { compile 'junit:junit:3.8.2' } + dependencies { implementation 'junit:junit:3.8.2' } shadowJar { relocate 'junit.framework', 'foo.junit.framework' diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy index e9d098c62..1395f5c21 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy @@ -184,7 +184,7 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { when: changeConfigurationTo """ - dependencies { compile 'junit:junit:3.8.2' } + dependencies { implementation 'junit:junit:3.8.2' } shadowJar { dependencies { diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 5cf84fddf..81ec812b0 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -35,11 +35,11 @@ class PluginSpecification extends Specification { println buildFile.text } - String getDefaultBuildScript() { + String getDefaultBuildScript(String javaPlugin = 'java') { return """ plugins { - id 'java' - id 'com.github.johnrengelman.shadow' + id '${javaPlugin}' + id 'com.github.johnrengelman.shadow' version '${SHADOW_VERSION}' } version = "1.0" @@ -91,7 +91,7 @@ class PluginSpecification extends Specification { } } - private static boolean containsDeprecationWarning(String output) { + static boolean containsDeprecationWarning(String output) { output.contains("has been deprecated and is scheduled to be removed in Gradle") || output.contains("has been deprecated. This is scheduled to be removed in Gradle") } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java index 32450ce8a..b6d395d90 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java @@ -36,6 +36,7 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.*; public class TestFile extends File {