From dde08a291fb498139bf747be52360acc183bb042 Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 7 Jul 2020 16:15:00 +0900 Subject: [PATCH 01/10] Adapt to Gradle 5 --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/plugins/PublishPlugin.groovy | 342 +++++++++--------- 2 files changed, 170 insertions(+), 174 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a74b47..19ca88f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy index 0e80e98..2d859e5 100644 --- a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy +++ b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy @@ -2,199 +2,195 @@ package de.lemona.gradle.plugins import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact -import org.gradle.api.internal.java.JavaLibrary import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.bundling.Jar class PublishPlugin implements Plugin { - void apply(Project project) { - // We just trigger our configurations on version/properties - project.plugins.withId('maven-publish') { - project.configure(project) { + void apply(Project project) { + // We just trigger our configurations on version/properties + project.plugins.withId('maven-publish') { + project.configure(project) { - // Our local (test) maven repository - def _repositoryPath = new File(buildDir, 'maven') + // Our local (test) maven repository + def _repositoryPath = new File(buildDir, 'maven') - // Inform where we are publishing to - logger.info('Publishing artifacts to \"{}\"', _repositoryPath.toURI()) + // Inform where we are publishing to + logger.info('Publishing artifacts to \"{}\"', _repositoryPath.toURI()) - // Inject our repository - publishing { - repositories { - maven { - url _repositoryPath - } - } - } - - /* ================================================================== */ - /* JAVA PROJECT PUBLISHING */ - /* ================================================================== */ - - plugins.withId('java') { - - // Sources JAR for publishing - task([type: Jar], 'publishSourcesJar') { - classifier = 'sources' - from sourceSets.main.allSource - } - - // JavaDoc JAR for publishing - task([type: Jar, dependsOn: javadoc], 'publishJavadocJar') { - classifier = 'javadoc' - from javadoc.destinationDir - } - - // Create a "java" maven publication *AFTER* the project has been - // evaluated. If we do this now, dependencies will not be included... - afterEvaluate { - publishing.publications.create('java', MavenPublication) { - from components.java - artifact publishSourcesJar - artifact publishJavadocJar - } - } - } - - /* ================================================================== */ - /* ANDROID LIBRARY PROJECT PUBLISHING */ - /* ================================================================== */ - - plugins.withId('com.android.library') { - - // By default we publish the "release" variant - def _variant = Utilities.resolveValue(project, 'publishVariant', 'PUBLISH_VARIANT', 'release') - def _variantName = _variant.capitalize() - - // Process all the library variants - android.libraryVariants.all { variant -> - if (variant.name != _variant) { - logger.info('Skipping publishing of "{}" variant', variant.name) - return; - } - - // Sources JAR for publishing - def _publishSourcesJar = task([type: Jar], 'publish' + _variantName + 'SourcesJar') { - classifier = 'sources' - from android.sourceSets.main.javaDirectories - from android.sourceSets.main.resourcesDirectories - } - - def _jarTaskName = 'package' + _variantName + 'Jar' - if (tasks.findByName(_jarTaskName) == null) { - println 'No Jar task found, creating one: ' + _jarTaskName - task([type: Jar], _jarTaskName) { - dependsOn variant.javaCompiler - from variant.javaCompiler.destinationDir - exclude '**/R.class', '**/R$*.class', '**/R.html', '**/R.*.html' - } - } - - // Prepare our publication artifact (from the AAR) - def _packageTask = tasks[_jarTaskName] - def _artifact = new ArchivePublishArtifact(_packageTask); - def _dependencies = configurations.compile.dependencies - def _component = new JavaLibrary(_artifact, _dependencies); - - // Also get the AAR itself, to publish alongside - def _bundleTask = tasks['bundle' + _variantName + 'Aar'] - - // Publish in our maven repository - def _versionCode = version.versionCode - publishing.publications.create(_variant, MavenPublication) { - from _component - artifact _bundleTask - artifact _publishSourcesJar - pom { - packaging = 'jar' - withXml { - asNode().appendNode('properties') - .appendNode('versionCode', _versionCode) + // Inject our repository + publishing { + repositories { + maven { + url _repositoryPath + } + } } - } - } - // The "javadocVariantName" task might not be here quite just yet - tasks.all { _javadocTask -> - // Ignore if not named "javadocVariantName" - if (_javadocTask.name != 'javadoc' + _variantName) return - - // Create a "publishVariantNameJavadocJar" task from the _javadocTask - def _publishJavadocJar = task([type: Jar], 'publish' + _variantName + 'JavadocJar') { - dependsOn _javadocTask - classifier = 'javadoc' - from _javadocTask.destinationDir - } - - // Add the Javadoc JAR artifact to our publication - publishing.publications.getByName(_variant) { publication -> - publication.artifact _publishJavadocJar - } - } - } - } + /* ================================================================== */ + /* JAVA PROJECT PUBLISHING */ + /* ================================================================== */ - /* ================================================================== */ - /* ANDROID APPLICATION PROJECT PUBLISHING */ - /* ================================================================== */ + plugins.withId('java') { - plugins.withId('com.android.application') { + // Sources JAR for publishing + task([type: Jar], 'publishSourcesJar') { + classifier = 'sources' + from sourceSets.main.allSource + } - // By default we publish the "release" variant - def _variant = Utilities.resolveValue(project, 'publishVariant', 'PUBLISH_VARIANT', 'release') - def _variantName = _variant.capitalize() + // JavaDoc JAR for publishing + task([type: Jar, dependsOn: javadoc], 'publishJavadocJar') { + classifier = 'javadoc' + from javadoc.destinationDir + } - // Process all the application variants - android.applicationVariants.all { variant -> - if (variant.name != _variant) { - logger.info('Skipping publishing of "{}" variant', variant.name) - return; - } + // Create a "java" maven publication *AFTER* the project has been + // evaluated. If we do this now, dependencies will not be included... + afterEvaluate { + publishing.publications.create('java', MavenPublication) { + from components.java + artifact publishSourcesJar + artifact publishJavadocJar + } + } + } - // The package task (creates APK) and version code - def _packageTask = tasks['package' + _variantName] - def _versionCode = version.versionCode - - // Make sure we *depend* on the package task - tasks['publish'].dependsOn _packageTask - - // Create our APK publication - publishing.publications.create(_variant, MavenPublication) { - _packageTask.outputs.files.each { - logger.debug("debugInfo: output files {}", it.toString()) - def files = it.listFiles(new FileFilter() { - @Override - boolean accept(File file) { - if (file.name.endsWith(".apk") && file.name.contains(_variant)) { - return true; + /* ================================================================== */ + /* ANDROID LIBRARY PROJECT PUBLISHING */ + /* ================================================================== */ + + plugins.withId('com.android.library') { + + // By default we publish the "release" variant + def _variant = Utilities.resolveValue(project, 'publishVariant', 'PUBLISH_VARIANT', 'release') + def _variantName = _variant.capitalize() + + // Process all the library variants + android.libraryVariants.all { variant -> + if (variant.name != _variant) { + logger.info('Skipping publishing of "{}" variant', variant.name) + return; + } + + // Sources JAR for publishing + def _publishSourcesJar = task([type: Jar], 'publish' + _variantName + 'SourcesJar') { + classifier = 'sources' + from android.sourceSets.main.javaDirectories + from android.sourceSets.main.resourcesDirectories + } + + def _jarTaskName = 'package' + _variantName + 'Jar' + if (tasks.findByName(_jarTaskName) == null) { + println 'No Jar task found, creating one: ' + _jarTaskName + task([type: Jar], _jarTaskName) { + dependsOn variant.javaCompiler + from variant.javaCompiler.destinationDir + exclude '**/R.class', '**/R$*.class', '**/R.html', '**/R.*.html' + } + } + + // Prepare our publication artifact (from the AAR) + def _packageTask = tasks[_jarTaskName] + def _component = project.components.findByName("java") + + // Also get the AAR itself, to publish alongside + def _bundleTask = tasks['bundle' + _variantName + 'Aar'] + + // Publish in our maven repository + def _versionCode = version.versionCode + publishing.publications.create(_variant, MavenPublication) { + from _component + artifact _bundleTask + artifact _publishSourcesJar + pom { + packaging = 'jar' + withXml { + asNode().appendNode('properties') + .appendNode('versionCode', _versionCode) + } + } + } + + // The "javadocVariantName" task might not be here quite just yet + tasks.all { _javadocTask -> + // Ignore if not named "javadocVariantName" + if (_javadocTask.name != 'javadoc' + _variantName) return + + // Create a "publishVariantNameJavadocJar" task from the _javadocTask + def _publishJavadocJar = task([type: Jar], 'publish' + _variantName + 'JavadocJar') { + dependsOn _javadocTask + classifier = 'javadoc' + from _javadocTask.destinationDir + } + + // Add the Javadoc JAR artifact to our publication + publishing.publications.getByName(_variant) { publication -> + publication.artifact _publishJavadocJar + } + } } - return false - } - }) - if (files != null && files.length > 0) { - File apk = files[0] - artifact apk.absolutePath - pom { - packaging = 'apk' - withXml { - asNode().appendNode('properties') - .appendNode('versionCode', _versionCode) + } + + /* ================================================================== */ + /* ANDROID APPLICATION PROJECT PUBLISHING */ + /* ================================================================== */ + + plugins.withId('com.android.application') { + + // By default we publish the "release" variant + def _variant = Utilities.resolveValue(project, 'publishVariant', 'PUBLISH_VARIANT', 'release') + def _variantName = _variant.capitalize() + + // Process all the application variants + android.applicationVariants.all { variant -> + if (variant.name != _variant) { + logger.info('Skipping publishing of "{}" variant', variant.name) + return; + } + + // The package task (creates APK) and version code + def _packageTask = tasks['package' + _variantName] + def _versionCode = version.versionCode + + // Make sure we *depend* on the package task + tasks['publish'].dependsOn _packageTask + + // Create our APK publication + publishing.publications.create(_variant, MavenPublication) { + _packageTask.outputs.files.each { + logger.debug("debugInfo: output files {}", it.toString()) + def files = it.listFiles(new FileFilter() { + @Override + boolean accept(File file) { + if (file.name.endsWith(".apk") && file.name.contains(_variant)) { + return true; + } + return false + } + }) + if (files != null && files.length > 0) { + File apk = files[0] + artifact apk.absolutePath + pom { + packaging = 'apk' + withXml { + asNode().appendNode('properties') + .appendNode('versionCode', _versionCode) + } + } + } + } + } } - } } - } } - } } - } } - } - def canBeResolved(configuration) { - // isCanBeResolved() was introduced with Gradle 3.3 so check for its existence first - configuration.metaClass.respondsTo(configuration, "isCanBeResolved") ? - configuration.isCanBeResolved() : true - } + def canBeResolved(configuration) { + // isCanBeResolved() was introduced with Gradle 3.3 so check for its existence first + configuration.metaClass.respondsTo(configuration, "isCanBeResolved") ? + configuration.isCanBeResolved() : true + } } \ No newline at end of file From ee6cccc6faaceaf8a8d73094ec04ae64e95d0684 Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 14 Jul 2020 18:04:13 +0900 Subject: [PATCH 02/10] refactor(publish): android app, lib publification --- .../gradle/plugins/PublishPlugin.groovy | 131 ++++-------------- 1 file changed, 24 insertions(+), 107 deletions(-) diff --git a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy index 2d859e5..b2fd827 100644 --- a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy +++ b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy @@ -61,74 +61,21 @@ class PublishPlugin implements Plugin { /* ================================================================== */ plugins.withId('com.android.library') { - - // By default we publish the "release" variant - def _variant = Utilities.resolveValue(project, 'publishVariant', 'PUBLISH_VARIANT', 'release') - def _variantName = _variant.capitalize() - - // Process all the library variants - android.libraryVariants.all { variant -> - if (variant.name != _variant) { - logger.info('Skipping publishing of "{}" variant', variant.name) - return; - } - - // Sources JAR for publishing - def _publishSourcesJar = task([type: Jar], 'publish' + _variantName + 'SourcesJar') { - classifier = 'sources' - from android.sourceSets.main.javaDirectories - from android.sourceSets.main.resourcesDirectories - } - - def _jarTaskName = 'package' + _variantName + 'Jar' - if (tasks.findByName(_jarTaskName) == null) { - println 'No Jar task found, creating one: ' + _jarTaskName - task([type: Jar], _jarTaskName) { - dependsOn variant.javaCompiler - from variant.javaCompiler.destinationDir - exclude '**/R.class', '**/R$*.class', '**/R.html', '**/R.*.html' - } - } - - // Prepare our publication artifact (from the AAR) - def _packageTask = tasks[_jarTaskName] - def _component = project.components.findByName("java") - - // Also get the AAR itself, to publish alongside - def _bundleTask = tasks['bundle' + _variantName + 'Aar'] - - // Publish in our maven repository - def _versionCode = version.versionCode - publishing.publications.create(_variant, MavenPublication) { - from _component - artifact _bundleTask - artifact _publishSourcesJar - pom { - packaging = 'jar' - withXml { - asNode().appendNode('properties') - .appendNode('versionCode', _versionCode) + afterEvaluate { + publishing { + publications { + def _group = group + def _name = name + def _version = version + release(MavenPublication) { + from components.release + + groupId = _group + artifactId = _name + version = _version } } } - - // The "javadocVariantName" task might not be here quite just yet - tasks.all { _javadocTask -> - // Ignore if not named "javadocVariantName" - if (_javadocTask.name != 'javadoc' + _variantName) return - - // Create a "publishVariantNameJavadocJar" task from the _javadocTask - def _publishJavadocJar = task([type: Jar], 'publish' + _variantName + 'JavadocJar') { - dependsOn _javadocTask - classifier = 'javadoc' - from _javadocTask.destinationDir - } - - // Add the Javadoc JAR artifact to our publication - publishing.publications.getByName(_variant) { publication -> - publication.artifact _publishJavadocJar - } - } } } @@ -137,48 +84,18 @@ class PublishPlugin implements Plugin { /* ================================================================== */ plugins.withId('com.android.application') { - - // By default we publish the "release" variant - def _variant = Utilities.resolveValue(project, 'publishVariant', 'PUBLISH_VARIANT', 'release') - def _variantName = _variant.capitalize() - - // Process all the application variants - android.applicationVariants.all { variant -> - if (variant.name != _variant) { - logger.info('Skipping publishing of "{}" variant', variant.name) - return; - } - - // The package task (creates APK) and version code - def _packageTask = tasks['package' + _variantName] - def _versionCode = version.versionCode - - // Make sure we *depend* on the package task - tasks['publish'].dependsOn _packageTask - - // Create our APK publication - publishing.publications.create(_variant, MavenPublication) { - _packageTask.outputs.files.each { - logger.debug("debugInfo: output files {}", it.toString()) - def files = it.listFiles(new FileFilter() { - @Override - boolean accept(File file) { - if (file.name.endsWith(".apk") && file.name.contains(_variant)) { - return true; - } - return false - } - }) - if (files != null && files.length > 0) { - File apk = files[0] - artifact apk.absolutePath - pom { - packaging = 'apk' - withXml { - asNode().appendNode('properties') - .appendNode('versionCode', _versionCode) - } - } + afterEvaluate { + publishing { + publications { + def _group = group + def _name = name + def _version = version + release(MavenPublication) { + from components.release_apk + + groupId = _group + artifactId = _name + version = _version } } } From bd6df92d7517db60985c4efe81b6ac7ceccfc261 Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 14 Jul 2020 18:04:39 +0900 Subject: [PATCH 03/10] docs: update read.me rewrite old stuff --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 996989c..33ab6b6 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ -Lemonade Lab Gradle Plugins +LEOMO Gradle Plugins =========================== This project contains a set of [Gradle](http://gradle.org/) plugins to customize the standard build conventions to the ones used at -[Lemonade Lab](http://lemona.de/) +[LEOMO, Inc.](http://leomo.io/) * [Main Plugin](#main-plugin) * [Android Plugin](#android-plugin) * [Publishing Plugin](#publishing-plugin) * [S3 Repository Plugin](#s3-repository-plugin) - Supported Version ----------------- * Gradle 2.13 - 4.0.1 @@ -66,10 +65,11 @@ This plugin will: > be left untouched. 3. Initialize the project's `version` filed following Lemonade's [versioning convertions](#versioning) -4. Set up three repositories for dependency resolution: +4. Set up repositories for dependency resolution: * Lemonade's OSS repository on [Bintray](https://bintray.com/lemonade/maven). * Bintray's [JCenter](https://bintray.com/lemonade/maven) repository. * The [Maven Central](http://search.maven.org/) repository. + * [Google's Maven](https://maven.google.com/) repository. 5. Set up the rest of our plugins: * Add the [Android Plugin](#android-plugin) if either the `com.android.application` or `com.android.library` plugins were specified @@ -152,13 +152,11 @@ repository under `${buildDir}/maven`. For Java artifacts the main java component, sources and javadoc jars will be published. -For Android _libraries_ the the jar, aar, sources and javadoc jars will be -published under the `${buildDir}/maven/${variant.name}` directory. +For Android _libraries_ the aar file will be published. -By default the `release` variant will be published, to publish a _different_ -build variant specify its name in the `publishVariant` project property or -`PUBLISH_VARIANT` environment variable. +For Android _app_ an zip file which contains the apk file and the obfuscation mapping file. +The `release` variant will be published. S3 Repository Plugin -------------------- From dc40393be34bc500d5b4293e9a15b63ceedc65de Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 14 Jul 2020 18:15:26 +0900 Subject: [PATCH 04/10] refactor: delete unused --- .../groovy/de/lemona/gradle/plugins/PublishPlugin.groovy | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy index b2fd827..f2e9fac 100644 --- a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy +++ b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy @@ -104,10 +104,4 @@ class PublishPlugin implements Plugin { } } } - - def canBeResolved(configuration) { - // isCanBeResolved() was introduced with Gradle 3.3 so check for its existence first - configuration.metaClass.respondsTo(configuration, "isCanBeResolved") ? - configuration.isCanBeResolved() : true - } } \ No newline at end of file From d57b7e70f2917939bbe30aaf07656b2453a168f9 Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 14 Jul 2020 18:15:36 +0900 Subject: [PATCH 05/10] build: bump up minor version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 420e535..81c507a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group = de.lemona -version = 0.2 +version = 0.3 From 995e694f0cfe32e85a380211827db9f1aad1ca08 Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 14 Jul 2020 18:41:58 +0900 Subject: [PATCH 06/10] docs: update updating.md about 0.3.0 --- updating.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/updating.md b/updating.md index 06bd8af..2b647dd 100644 --- a/updating.md +++ b/updating.md @@ -1,5 +1,15 @@ # Updating individual projects +## Version 0.3.0 +0.3.0 supports Gradle 5. +You can use the latest (as 2020) Android gradle plugin in dependent Android projects. +However, the publishing plugin doesn't have a backward compatibility for Android projects. +So, please update the followings: + +* Gradle -> 5.6.4 +* Android Plugin -> 3.6.0 +* Android Build Tools -> 28.0.3 or later + ## Version 0.1.0 The 0.1.0 version of this plugin is fully backward compatible. Simply bumping its version in dependent projects will have no side effects. From cfffd83d811d72bf08dbeefe9da61a1862795d9e Mon Sep 17 00:00:00 2001 From: tkc Date: Tue, 14 Jul 2020 18:42:23 +0900 Subject: [PATCH 07/10] build: update plugin details --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index f51b332..f46fc4d 100644 --- a/build.gradle +++ b/build.gradle @@ -24,12 +24,12 @@ gradle.taskGraph.whenReady { taskGraph -> pluginBundle { website = 'https://www.leomo.io/' vcsUrl = 'https://github.com/LemonadeLabInc/gradle-snippets' - description = 'Lemonade Android and Java conventions plugin' - tags = ['lemonade'] + description = 'LEOMO Android and Java conventions plugin' + tags = ['leomo'] plugins { gradle { id = 'de.lemona.gradle' - displayName = 'Lemonade Gradle plugin' + displayName = 'LEOMO Gradle plugin' } } } From dab37d227e24dfb0f47d6d2ae53d04fa5efdbd83 Mon Sep 17 00:00:00 2001 From: tkc Date: Wed, 15 Jul 2020 13:47:40 +0900 Subject: [PATCH 08/10] style: format PublishPlugin --- .gitignore | 2 +- .../gradle/plugins/PublishPlugin.groovy | 178 +++++++++--------- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index 6880c12..473b1f9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ build/ local.properties -# Lemonade +# Private lemonade.properties diff --git a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy index f2e9fac..49a0257 100644 --- a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy +++ b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy @@ -7,101 +7,101 @@ import org.gradle.api.tasks.bundling.Jar class PublishPlugin implements Plugin { - void apply(Project project) { - // We just trigger our configurations on version/properties - project.plugins.withId('maven-publish') { - project.configure(project) { - - // Our local (test) maven repository - def _repositoryPath = new File(buildDir, 'maven') - - // Inform where we are publishing to - logger.info('Publishing artifacts to \"{}\"', _repositoryPath.toURI()) - - // Inject our repository - publishing { - repositories { - maven { - url _repositoryPath - } - } - } + void apply(Project project) { + // We just trigger our configurations on version/properties + project.plugins.withId('maven-publish') { + project.configure(project) { + + // Our local (test) maven repository + def _repositoryPath = new File(buildDir, 'maven') + + // Inform where we are publishing to + logger.info('Publishing artifacts to \"{}\"', _repositoryPath.toURI()) + + // Inject our repository + publishing { + repositories { + maven { + url _repositoryPath + } + } + } - /* ================================================================== */ - /* JAVA PROJECT PUBLISHING */ - /* ================================================================== */ - - plugins.withId('java') { - - // Sources JAR for publishing - task([type: Jar], 'publishSourcesJar') { - classifier = 'sources' - from sourceSets.main.allSource - } - - // JavaDoc JAR for publishing - task([type: Jar, dependsOn: javadoc], 'publishJavadocJar') { - classifier = 'javadoc' - from javadoc.destinationDir - } - - // Create a "java" maven publication *AFTER* the project has been - // evaluated. If we do this now, dependencies will not be included... - afterEvaluate { - publishing.publications.create('java', MavenPublication) { - from components.java - artifact publishSourcesJar - artifact publishJavadocJar - } - } - } + /* ================================================================== */ + /* JAVA PROJECT PUBLISHING */ + /* ================================================================== */ + + plugins.withId('java') { + + // Sources JAR for publishing + task([type: Jar], 'publishSourcesJar') { + classifier = 'sources' + from sourceSets.main.allSource + } + + // JavaDoc JAR for publishing + task([type: Jar, dependsOn: javadoc], 'publishJavadocJar') { + classifier = 'javadoc' + from javadoc.destinationDir + } + + // Create a "java" maven publication *AFTER* the project has been + // evaluated. If we do this now, dependencies will not be included... + afterEvaluate { + publishing.publications.create('java', MavenPublication) { + from components.java + artifact publishSourcesJar + artifact publishJavadocJar + } + } + } - /* ================================================================== */ - /* ANDROID LIBRARY PROJECT PUBLISHING */ - /* ================================================================== */ - - plugins.withId('com.android.library') { - afterEvaluate { - publishing { - publications { - def _group = group - def _name = name - def _version = version - release(MavenPublication) { - from components.release - - groupId = _group - artifactId = _name - version = _version - } - } - } - } + /* ================================================================== */ + /* ANDROID LIBRARY PROJECT PUBLISHING */ + /* ================================================================== */ + + plugins.withId('com.android.library') { + afterEvaluate { + publishing { + publications { + def _group = group + def _name = name + def _version = version + release(MavenPublication) { + from components.release + + groupId = _group + artifactId = _name + version = _version } + } + } + } + } - /* ================================================================== */ - /* ANDROID APPLICATION PROJECT PUBLISHING */ - /* ================================================================== */ - - plugins.withId('com.android.application') { - afterEvaluate { - publishing { - publications { - def _group = group - def _name = name - def _version = version - release(MavenPublication) { - from components.release_apk - - groupId = _group - artifactId = _name - version = _version - } - } - } - } + /* ================================================================== */ + /* ANDROID APPLICATION PROJECT PUBLISHING */ + /* ================================================================== */ + + plugins.withId('com.android.application') { + afterEvaluate { + publishing { + publications { + def _group = group + def _name = name + def _version = version + release(MavenPublication) { + from components.release_apk + + groupId = _group + artifactId = _name + version = _version } + } } + } } + } } + } } \ No newline at end of file From ac15a01ac6189179da736518f5d9641672b0e323 Mon Sep 17 00:00:00 2001 From: tkc Date: Wed, 15 Jul 2020 13:55:38 +0900 Subject: [PATCH 09/10] add comment --- src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy index 49a0257..2a3a8f6 100644 --- a/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy +++ b/src/main/groovy/de/lemona/gradle/plugins/PublishPlugin.groovy @@ -61,6 +61,7 @@ class PublishPlugin implements Plugin { /* ================================================================== */ plugins.withId('com.android.library') { + // cf. https://developer.android.com/studio/build/maven-publish-plugin afterEvaluate { publishing { publications { @@ -84,6 +85,7 @@ class PublishPlugin implements Plugin { /* ================================================================== */ plugins.withId('com.android.application') { + // cf. https://developer.android.com/studio/build/maven-publish-plugin afterEvaluate { publishing { publications { From 7c836169bee7f6a4d390d67c9793bd3e8c12c0b1 Mon Sep 17 00:00:00 2001 From: tkc Date: Wed, 15 Jul 2020 14:15:03 +0900 Subject: [PATCH 10/10] apply our JavaPlugin when projects use java-library plugin --- src/main/groovy/de/lemona/gradle/plugins/GradlePlugin.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/groovy/de/lemona/gradle/plugins/GradlePlugin.groovy b/src/main/groovy/de/lemona/gradle/plugins/GradlePlugin.groovy index 7fdc3da..ca06ca0 100644 --- a/src/main/groovy/de/lemona/gradle/plugins/GradlePlugin.groovy +++ b/src/main/groovy/de/lemona/gradle/plugins/GradlePlugin.groovy @@ -21,6 +21,7 @@ class GradlePlugin implements Plugin { // Trigger actions on our plugins plugins.withId('java') { project.apply plugin: 'de.lemona.gradle.java' } + plugins.withId('java-library') { project.apply plugin: 'de.lemona.gradle.java' } plugins.withId('maven-publish') { project.apply plugin: 'de.lemona.gradle.publish' } plugins.withId('com.android.application') {