From 06f85c4f6b63feb45fc9cb7f0efc70a94e61b640 Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Thu, 9 Nov 2017 02:20:40 +0900 Subject: [PATCH 1/9] add support for implementation an api configuration --- core/build.gradle | 13 ++++ .../gradle/release/AndroidLibrary.groovy | 18 ++++-- .../gradle/release/TestGeneratePomTask.groovy | 60 +++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy diff --git a/core/build.gradle b/core/build.gradle index 9408861..ece03ad 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -18,6 +18,18 @@ repositories { jcenter() } +// Write the plugin's classpath to a file to share with the tests +task createClasspathManifest { + def outputDir = file("$buildDir/$name") + + inputs.files sourceSets.main.runtimeClasspath + outputs.dir outputDir + + doLast { + outputDir.mkdirs() + file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n") + } +} dependencies { compile gradleApi() @@ -26,6 +38,7 @@ dependencies { testCompile gradleTestKit() testCompile 'junit:junit:4.12' + testRuntime files(createClasspathManifest) } compileGroovy { diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy index f3dc715..dac54c9 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy @@ -2,6 +2,7 @@ package com.novoda.gradle.release import org.gradle.api.DomainObjectSet import org.gradle.api.Project +import org.gradle.api.UnknownDomainObjectException import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.artifacts.PublishArtifact @@ -20,13 +21,22 @@ class AndroidLibrary implements SoftwareComponentInternal { ObjectFactory objectFactory = project.getObjects(); Usage usage = objectFactory.named(Usage.class, Usage.JAVA_RUNTIME); - def configuration = project.configurations.getByName("compile") - return configuration ? from(configuration, usage) : empty() + + try { + def implementationConfiguration = project.configurations.getByName("implementation") + configuration.dependencies.addAll(implementationConfiguration.dependencies) + def apiConfiguration = project.configurations.getByName("api") + configuration.dependencies.addAll(apiConfiguration.dependencies) + } catch (UnknownDomainObjectException ignore) { + // no implementation or api configuration + } + + return configuration ? from(configuration.dependencies, usage) : empty() } - static AndroidLibrary from(def configuration, Usage usage) { - def runtimeUsage = new RuntimeUsage(configuration.dependencies, usage) + static AndroidLibrary from(def dependencies, Usage usage) { + def runtimeUsage = new RuntimeUsage(dependencies, usage) new AndroidLibrary(runtimeUsage) } diff --git a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy new file mode 100644 index 0000000..58769e1 --- /dev/null +++ b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy @@ -0,0 +1,60 @@ +package com.novoda.gradle.release + +import org.gradle.testkit.runner.GradleRunner +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +class TestGeneratePomTask { + + @Rule public TemporaryFolder testProjectDir = new TemporaryFolder() + private List pluginClasspath + private File buildFile + + @Before + void setup() { + if (pluginClasspath == null) { + buildFile = testProjectDir.newFile('build.gradle') + def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt") + if (pluginClasspathResource == null) { + throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.") + } + pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } + } + } + + @Test + void testGeneratePomTask() { + buildFile << """ + plugins { + id 'java-library' + id 'bintray-release' + } + + publish { + userOrg = 'novoda' + groupId = 'com.novoda' + artifactId = 'test' + publishVersion = '1.0' + } + + dependencies { + compile 'com.abc:hello:1.0.0' + implementation 'com.xyz:world:2.0.0' + api 'com.xxx:haha:3.0.0' + } + """ + + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments("generatePomFileForMavenPublication") + .withPluginClasspath(pluginClasspath) + .build() + + print(testProjectDir) + assert result.task(":generatePomFileForMavenPublication").outcome == SUCCESS + } +} \ No newline at end of file From 652efb52579b3e2c6ef87ab54f1f0faf16fac393 Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Thu, 9 Nov 2017 23:33:04 +0900 Subject: [PATCH 2/9] check generated pom file content --- .../novoda/gradle/release/TestGeneratePomTask.groovy | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy index 58769e1..20973a9 100644 --- a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy +++ b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy @@ -17,12 +17,13 @@ class TestGeneratePomTask { @Before void setup() { if (pluginClasspath == null) { - buildFile = testProjectDir.newFile('build.gradle') def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt") if (pluginClasspathResource == null) { throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.") } pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } + + buildFile = testProjectDir.newFile('build.gradle') } } @@ -56,5 +57,14 @@ class TestGeneratePomTask { print(testProjectDir) assert result.task(":generatePomFileForMavenPublication").outcome == SUCCESS + + File pomFile = new File(testProjectDir.root, '/build/publications/maven/pom-default.xml') + def nodes = new XmlSlurper().parse(pomFile) + def dependencies = nodes.dependencies.dependency + + assert dependencies.size() == 3 + assert dependencies.find { dep -> dep.artifactId == "hello" && dep.scope == "compile" } != null + assert dependencies.find { dep -> dep.artifactId == "haha" && dep.scope == "compile" } != null + assert dependencies.find { dep -> dep.artifactId == "world" && dep.scope == "runtime" } != null } } \ No newline at end of file From 71601435ba2e45587bc2eaea59bf4ec913c1c170 Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Fri, 10 Nov 2017 12:52:55 +0900 Subject: [PATCH 3/9] add android lib testcase --- .../gradle/release/TestGeneratePomTask.groovy | 87 ++++++++++++++++--- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy index 20973a9..d413d6d 100644 --- a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy +++ b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy @@ -11,7 +11,7 @@ import static org.gradle.testkit.runner.TaskOutcome.SUCCESS class TestGeneratePomTask { @Rule public TemporaryFolder testProjectDir = new TemporaryFolder() - private List pluginClasspath + private String pluginClasspath private File buildFile @Before @@ -21,20 +21,27 @@ class TestGeneratePomTask { if (pluginClasspathResource == null) { throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.") } - pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) } - - buildFile = testProjectDir.newFile('build.gradle') + def classpath = pluginClasspathResource.readLines().collect { new File(it) } + pluginClasspath = classpath + .collect { it.absolutePath.replace('\\', '\\\\') } // escape backslashes in Windows paths + .collect { "'$it'" } + .join(", ") } + buildFile = testProjectDir.newFile('build.gradle') } @Test - void testGeneratePomTask() { + void testGeneratePomTaskForJavaLib() { buildFile << """ - plugins { - id 'java-library' - id 'bintray-release' + buildscript { + dependencies { + classpath files($pluginClasspath) + } } + apply plugin: "java-library" + apply plugin: "bintray-release" + publish { userOrg = 'novoda' groupId = 'com.novoda' @@ -52,10 +59,8 @@ class TestGeneratePomTask { def result = GradleRunner.create() .withProjectDir(testProjectDir.root) .withArguments("generatePomFileForMavenPublication") - .withPluginClasspath(pluginClasspath) .build() - print(testProjectDir) assert result.task(":generatePomFileForMavenPublication").outcome == SUCCESS File pomFile = new File(testProjectDir.root, '/build/publications/maven/pom-default.xml') @@ -67,4 +72,66 @@ class TestGeneratePomTask { assert dependencies.find { dep -> dep.artifactId == "haha" && dep.scope == "compile" } != null assert dependencies.find { dep -> dep.artifactId == "world" && dep.scope == "runtime" } != null } + + @Test + void testGeneratePomTaskForAndroidLibrary() { + File manifestFile = new File(testProjectDir.root, "/src/main/AndroidManifest.xml") + manifestFile.getParentFile().mkdirs() + manifestFile.createNewFile() + manifestFile << """ + + """ + + buildFile << """ + buildscript { + repositories { + jcenter() + google() + } + dependencies { + classpath files($pluginClasspath) + classpath 'com.android.tools.build:gradle:3.0.0' + } + } + apply plugin: "com.android.library" + apply plugin: "bintray-release" + + android { + compileSdkVersion 26 + buildToolsVersion "26.0.2" + + defaultConfig { + minSdkVersion 16 + versionCode 1 + versionName "0.0.1" + } + } + + publish { + userOrg = 'novoda' + groupId = 'com.novoda' + artifactId = 'test' + publishVersion = '1.0' + } + + dependencies { + compile 'com.abc:hello:1.0.0' + implementation 'com.xyz:world:2.0.0' + api 'com.xxx:haha:3.0.0' + } + """ + + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments("generatePomFileForReleasePublication") + .build() + + assert result.task(":generatePomFileForReleasePublication").outcome == SUCCESS + + File pomFile = new File(testProjectDir.root, '/build/publications/release/pom-default.xml') + def nodes = new XmlSlurper().parse(pomFile) + def dependencies = nodes.dependencies.dependency + + assert dependencies.size() == 3 + } } \ No newline at end of file From 647c45a55959e750dfad4a29a28e5a4a4cc90cd1 Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Tue, 14 Nov 2017 14:06:21 +0900 Subject: [PATCH 4/9] use different usages depend on configuration --- .../gradle/release/AndroidArtifacts.groovy | 2 +- .../gradle/release/AndroidLibrary.groovy | 76 +++++++++---------- .../gradle/release/TestGeneratePomTask.groovy | 3 + 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidArtifacts.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidArtifacts.groovy index 2b0882c..d860099 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidArtifacts.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidArtifacts.groovy @@ -46,7 +46,7 @@ class AndroidArtifacts implements Artifacts { } def from(Project project) { - project.components.add(AndroidLibrary.newInstance(project)) + project.components.add(new AndroidLibrary(project)) project.components.android } diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy index dac54c9..ce3f896 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy @@ -14,69 +14,61 @@ import org.gradle.api.model.ObjectFactory class AndroidLibrary implements SoftwareComponentInternal { - private final UsageContext runtimeUsage + private final Set usages - public static AndroidLibrary newInstance(Project project) { + AndroidLibrary(Project project) { + this.usages = new DefaultDomainObjectSet(UsageContext) - ObjectFactory objectFactory = project.getObjects(); - Usage usage = objectFactory.named(Usage.class, Usage.JAVA_RUNTIME); + ObjectFactory objectFactory = project.getObjects() + Usage api = objectFactory.named(Usage.class, Usage.JAVA_API) + Usage runtime = objectFactory.named(Usage.class, Usage.JAVA_RUNTIME) - def configuration = project.configurations.getByName("compile") - - try { - def implementationConfiguration = project.configurations.getByName("implementation") - configuration.dependencies.addAll(implementationConfiguration.dependencies) - def apiConfiguration = project.configurations.getByName("api") - configuration.dependencies.addAll(apiConfiguration.dependencies) - } catch (UnknownDomainObjectException ignore) { - // no implementation or api configuration - } - - return configuration ? from(configuration.dependencies, usage) : empty() - } - - static AndroidLibrary from(def dependencies, Usage usage) { - def runtimeUsage = new RuntimeUsage(dependencies, usage) - new AndroidLibrary(runtimeUsage) + addUsageContextFromConfiguration(project, "compile", api) + addUsageContextFromConfiguration(project, "api", api) + addUsageContextFromConfiguration(project, "implementation", runtime) } - static AndroidLibrary empty() { - def usage = new RuntimeUsage(new DefaultDomainObjectSet(Dependency)) - new AndroidLibrary(usage) - } - - AndroidLibrary(UsageContext runtimeUsage) { - this.runtimeUsage = runtimeUsage + String getName() { + return "android" } - public String getName() { - return "android" + Set getUsages() { + return usages } - public Set getUsages() { - return Collections.singleton(runtimeUsage); + private addUsageContextFromConfiguration(Project project, String configuration, Usage usage) { + try { + def configurationObj = project.configurations.getByName(configuration) + def dependency = configurationObj.dependencies + if (!dependency.isEmpty()) { + def libraryUsage = new LibraryUsage(dependency, usage) + usages.add(libraryUsage) + } + } catch (UnknownDomainObjectException ignore) { + // cannot find configuration + } } - private static class RuntimeUsage implements UsageContext { + private static class LibraryUsage implements UsageContext { - private final DomainObjectSet runtimeDependencies - private final Usage usage; + private final DomainObjectSet dependencies + private final Usage usage - RuntimeUsage(DomainObjectSet runtimeDependencies, Usage usage) { - this.usage = usage; - this.runtimeDependencies = runtimeDependencies + LibraryUsage(DomainObjectSet dependencies, Usage usage) { + this.usage = usage + this.dependencies = dependencies } Usage getUsage() { - return usage; + return usage } - public Set getArtifacts() { + Set getArtifacts() { new LinkedHashSet() } - public Set getDependencies() { - runtimeDependencies.withType(ModuleDependency) + Set getDependencies() { + dependencies.withType(ModuleDependency) } } } diff --git a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy index d413d6d..06e9f2c 100644 --- a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy +++ b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy @@ -133,5 +133,8 @@ class TestGeneratePomTask { def dependencies = nodes.dependencies.dependency assert dependencies.size() == 3 + assert dependencies.find { dep -> dep.artifactId == "hello" && dep.scope == "compile" } != null + assert dependencies.find { dep -> dep.artifactId == "haha" && dep.scope == "compile" } != null + assert dependencies.find { dep -> dep.artifactId == "world" && dep.scope == "runtime" } != null } } \ No newline at end of file From 49408d1a6e065260f4242224f011db69c49539ac Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Wed, 15 Nov 2017 23:45:27 +0900 Subject: [PATCH 5/9] change config strings to constants --- .../novoda/gradle/release/AndroidLibrary.groovy | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy index ce3f896..6bfe0ea 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy @@ -14,18 +14,20 @@ import org.gradle.api.model.ObjectFactory class AndroidLibrary implements SoftwareComponentInternal { - private final Set usages + private final String CONF_COMPILE = "compile" + private final String CONF_API = "api" + private final String CONF_IMPLEMENTATION = "implementation" - AndroidLibrary(Project project) { - this.usages = new DefaultDomainObjectSet(UsageContext) + private final Set usages = new DefaultDomainObjectSet(UsageContext) + AndroidLibrary(Project project) { ObjectFactory objectFactory = project.getObjects() Usage api = objectFactory.named(Usage.class, Usage.JAVA_API) Usage runtime = objectFactory.named(Usage.class, Usage.JAVA_RUNTIME) - addUsageContextFromConfiguration(project, "compile", api) - addUsageContextFromConfiguration(project, "api", api) - addUsageContextFromConfiguration(project, "implementation", runtime) + addUsageContextFromConfiguration(project, CONF_COMPILE, api) + addUsageContextFromConfiguration(project, CONF_API, api) + addUsageContextFromConfiguration(project, CONF_IMPLEMENTATION, runtime) } String getName() { From c36a3d7410cc32f294e9b52d71e50243276acdb1 Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Thu, 16 Nov 2017 01:16:35 +0900 Subject: [PATCH 6/9] support using different Usage in gradle 4.1 --- .../groovy/com/novoda/gradle/release/AndroidLibrary.groovy | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy index 6bfe0ea..9d5792b 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy @@ -11,6 +11,7 @@ import org.gradle.api.internal.DefaultDomainObjectSet import org.gradle.api.internal.component.SoftwareComponentInternal import org.gradle.api.internal.component.UsageContext import org.gradle.api.model.ObjectFactory +import org.gradle.util.GradleVersion class AndroidLibrary implements SoftwareComponentInternal { @@ -22,8 +23,10 @@ class AndroidLibrary implements SoftwareComponentInternal { AndroidLibrary(Project project) { ObjectFactory objectFactory = project.getObjects() - Usage api = objectFactory.named(Usage.class, Usage.JAVA_API) - Usage runtime = objectFactory.named(Usage.class, Usage.JAVA_RUNTIME) + + def newVersion = GradleVersion.current() > GradleVersion.version("4.1") + Usage api = objectFactory.named(Usage.class, newVersion ? Usage.JAVA_API : "for compile") + Usage runtime = objectFactory.named(Usage.class, newVersion ? Usage.JAVA_RUNTIME : "for runtime") addUsageContextFromConfiguration(project, CONF_COMPILE, api) addUsageContextFromConfiguration(project, CONF_API, api) From 7e41ee292c50ee4b463134d13186bd6ecc3d3e89 Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Sun, 19 Nov 2017 16:04:06 +0900 Subject: [PATCH 7/9] use java-gradle-plugin to auto inject classpath for testing --- core/build.gradle | 15 +-------- .../gradle/release/TestGeneratePomTask.groovy | 32 +++++++------------ 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index ece03ad..8c1969b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.novoda.bintray-release' apply plugin: 'groovy' +apply plugin: 'java-gradle-plugin' apply plugin: 'maven' buildscript { @@ -18,19 +19,6 @@ repositories { jcenter() } -// Write the plugin's classpath to a file to share with the tests -task createClasspathManifest { - def outputDir = file("$buildDir/$name") - - inputs.files sourceSets.main.runtimeClasspath - outputs.dir outputDir - - doLast { - outputDir.mkdirs() - file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n") - } -} - dependencies { compile gradleApi() compile localGroovy() @@ -38,7 +26,6 @@ dependencies { testCompile gradleTestKit() testCompile 'junit:junit:4.12' - testRuntime files(createClasspathManifest) } compileGroovy { diff --git a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy index 06e9f2c..1dbb4b5 100644 --- a/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy +++ b/core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy @@ -11,37 +11,21 @@ import static org.gradle.testkit.runner.TaskOutcome.SUCCESS class TestGeneratePomTask { @Rule public TemporaryFolder testProjectDir = new TemporaryFolder() - private String pluginClasspath private File buildFile @Before void setup() { - if (pluginClasspath == null) { - def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt") - if (pluginClasspathResource == null) { - throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.") - } - def classpath = pluginClasspathResource.readLines().collect { new File(it) } - pluginClasspath = classpath - .collect { it.absolutePath.replace('\\', '\\\\') } // escape backslashes in Windows paths - .collect { "'$it'" } - .join(", ") - } buildFile = testProjectDir.newFile('build.gradle') } @Test void testGeneratePomTaskForJavaLib() { - buildFile << """ - buildscript { - dependencies { - classpath files($pluginClasspath) - } + buildFile << """ + plugins { + id 'java-library' + id 'bintray-release' } - apply plugin: "java-library" - apply plugin: "bintray-release" - publish { userOrg = 'novoda' groupId = 'com.novoda' @@ -59,6 +43,7 @@ class TestGeneratePomTask { def result = GradleRunner.create() .withProjectDir(testProjectDir.root) .withArguments("generatePomFileForMavenPublication") + .withPluginClasspath() .build() assert result.task(":generatePomFileForMavenPublication").outcome == SUCCESS @@ -89,10 +74,14 @@ class TestGeneratePomTask { google() } dependencies { - classpath files($pluginClasspath) classpath 'com.android.tools.build:gradle:3.0.0' } } + + plugins { + id 'bintray-release' apply false + } + apply plugin: "com.android.library" apply plugin: "bintray-release" @@ -124,6 +113,7 @@ class TestGeneratePomTask { def result = GradleRunner.create() .withProjectDir(testProjectDir.root) .withArguments("generatePomFileForReleasePublication") + .withPluginClasspath() .build() assert result.task(":generatePomFileForReleasePublication").outcome == SUCCESS From 6f9ad3db15544d8eb9189036bf47d2215db3bcad Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Thu, 23 Nov 2017 15:11:24 +0900 Subject: [PATCH 8/9] Add comment about Usage in Gradle 4.1 --- .../com/novoda/gradle/release/AndroidLibrary.groovy | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy index 9d5792b..5a543b3 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy @@ -24,9 +24,13 @@ class AndroidLibrary implements SoftwareComponentInternal { AndroidLibrary(Project project) { ObjectFactory objectFactory = project.getObjects() - def newVersion = GradleVersion.current() > GradleVersion.version("4.1") - Usage api = objectFactory.named(Usage.class, newVersion ? Usage.JAVA_API : "for compile") - Usage runtime = objectFactory.named(Usage.class, newVersion ? Usage.JAVA_RUNTIME : "for runtime") + // Using the new Usage in 4.1 will make the plugin crash + // as comparing logic is still using the old Usage. + // 4.1 : https://git.io/vFAnQ + // 4.2 : https://git.io/vFAnd + def isNewerThan4_1 = GradleVersion.current() > GradleVersion.version("4.1") + Usage api = objectFactory.named(Usage.class, isNewerThan4_1 ? Usage.JAVA_API : "for compile") + Usage runtime = objectFactory.named(Usage.class, isNewerThan4_1 ? Usage.JAVA_RUNTIME : "for runtime") addUsageContextFromConfiguration(project, CONF_COMPILE, api) addUsageContextFromConfiguration(project, CONF_API, api) From b582c33897a188655498fb843560de90673ee9fe Mon Sep 17 00:00:00 2001 From: Amornchai Kanokpullwad Date: Fri, 24 Nov 2017 00:46:35 +0900 Subject: [PATCH 9/9] update gradle version checking comment --- .../groovy/com/novoda/gradle/release/AndroidLibrary.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy index 5a543b3..6889b8e 100644 --- a/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy +++ b/core/src/main/groovy/com/novoda/gradle/release/AndroidLibrary.groovy @@ -26,8 +26,7 @@ class AndroidLibrary implements SoftwareComponentInternal { // Using the new Usage in 4.1 will make the plugin crash // as comparing logic is still using the old Usage. - // 4.1 : https://git.io/vFAnQ - // 4.2 : https://git.io/vFAnd + // For more details: https://github.com/novoda/bintray-release/pull/147 def isNewerThan4_1 = GradleVersion.current() > GradleVersion.version("4.1") Usage api = objectFactory.named(Usage.class, isNewerThan4_1 ? Usage.JAVA_API : "for compile") Usage runtime = objectFactory.named(Usage.class, isNewerThan4_1 ? Usage.JAVA_RUNTIME : "for runtime")