This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
356 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ gradle-app.setting | |
|
||
.idea | ||
*.iml | ||
local.properties | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
### Android libraries support | ||
|
||
Android Gradle Plugin `3.6.0-beta05` or newer is required. | ||
|
||
Configuration specific to Android library projects (using `com.android.library` plugins): | ||
|
||
1. Apply `org.shipkit.android-publish` plugin to each Gradle project (submodule) you want to publish | ||
(usually they are not the root projects). | ||
1. Specify `artifactId` in `androidPublish` blocks. | ||
|
||
Example: | ||
|
||
```Gradle | ||
apply plugin: 'org.shipkit.bintray' | ||
apply plugin: 'org.shipkit.android-publish' | ||
apply plugin: 'com.android.library' | ||
androidPublish { | ||
artifactId = 'shipkit-android' | ||
} | ||
``` | ||
|
||
Other POM properties which can be set using Gradle API: | ||
* group id - [Project#group](https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:group) | ||
* name - [Project#archivesBaseName](https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:archivesBaseName) | ||
* description - [Project#description](https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...shipkit/src/main/groovy/org/shipkit/gradle/configuration/AndroidPublishConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.shipkit.gradle.configuration; | ||
|
||
import org.gradle.api.GradleException; | ||
|
||
public class AndroidPublishConfiguration { | ||
|
||
private String artifactId; | ||
|
||
/** | ||
* Artifact id of published AAR | ||
* For example: "shipkit-android" | ||
*/ | ||
public String getArtifactId() { | ||
if (artifactId == null || artifactId.isEmpty()) { | ||
throw new GradleException("Please configure artifact id"); | ||
} | ||
return artifactId; | ||
} | ||
|
||
/** | ||
* See {@link #getArtifactId()} ()} | ||
*/ | ||
public void setArtifactId(String artifactId) { | ||
this.artifactId = artifactId; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...cts/shipkit/src/main/groovy/org/shipkit/internal/gradle/android/AndroidPublishPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.shipkit.internal.gradle.android; | ||
|
||
import com.jfrog.bintray.gradle.BintrayExtension; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.component.SoftwareComponent; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
import org.gradle.api.publish.maven.MavenPublication; | ||
import org.shipkit.gradle.configuration.AndroidPublishConfiguration; | ||
import org.shipkit.gradle.configuration.ShipkitConfiguration; | ||
import org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin; | ||
import org.shipkit.internal.gradle.snapshot.LocalSnapshotPlugin; | ||
import org.shipkit.internal.gradle.util.GradleDSLHelper; | ||
import org.shipkit.internal.gradle.util.PomCustomizer; | ||
|
||
import static org.shipkit.internal.gradle.configuration.DeferredConfiguration.deferredConfiguration; | ||
import static org.shipkit.internal.gradle.java.JavaPublishPlugin.MAVEN_LOCAL_TASK; | ||
import static org.shipkit.internal.gradle.java.JavaPublishPlugin.PUBLICATION_NAME; | ||
|
||
/** | ||
* Publishing Android libraries using 'maven-publish' plugin. | ||
* Intended to be applied in individual Android library submodule. | ||
* Applies following plugins and tasks and configures them: | ||
* | ||
* <ul> | ||
* <li>maven-publish</li> | ||
* </ul> | ||
* | ||
* Other features: | ||
* <ul> | ||
* <li>Configures Gradle's publications to publish Android library</li> | ||
* <li>Configures 'build' task to depend on 'publishJavaLibraryToMavenLocal' | ||
* to flesh out publication issues during the build</li> | ||
* <li>Configures 'snapshot' task to depend on 'publishJavaLibraryToMavenLocal'</li> | ||
* </ul> | ||
*/ | ||
public class AndroidPublishPlugin implements Plugin<Project> { | ||
|
||
private final static Logger LOG = Logging.getLogger(AndroidPublishPlugin.class); | ||
private final static String ANDROID_PUBLISH_EXTENSION = "androidPublish"; | ||
|
||
public void apply(final Project project) { | ||
final AndroidPublishConfiguration androidPublishConfiguration = project.getExtensions().create(ANDROID_PUBLISH_EXTENSION, AndroidPublishConfiguration.class); | ||
|
||
final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration(); | ||
|
||
project.getPlugins().apply(LocalSnapshotPlugin.class); | ||
Task snapshotTask = project.getTasks().getByName(LocalSnapshotPlugin.SNAPSHOT_TASK); | ||
snapshotTask.dependsOn(MAVEN_LOCAL_TASK); | ||
|
||
project.getPlugins().apply("maven-publish"); | ||
|
||
BintrayExtension bintray = project.getExtensions().getByType(BintrayExtension.class); | ||
bintray.setPublications(PUBLICATION_NAME); | ||
|
||
project.getPlugins().withId("com.android.library", plugin -> { | ||
deferredConfiguration(project, () -> { | ||
GradleDSLHelper.publications(project, publications -> { | ||
MavenPublication p = publications.create(PUBLICATION_NAME, MavenPublication.class, publication -> { | ||
publication.setArtifactId(androidPublishConfiguration.getArtifactId()); | ||
|
||
SoftwareComponent releaseComponent = project.getComponents().findByName("release"); | ||
if (releaseComponent == null) { | ||
throw new GradleException("'release' component not found in project. " + | ||
"Make sure you are using Android Gradle Plugin 3.6.0-beta05 or newer."); | ||
} | ||
publication.from(releaseComponent); | ||
PomCustomizer.customizePom(project, conf, publication); | ||
}); | ||
LOG.info("{} - configured '{}' publication", project.getPath(), p.getArtifactId()); | ||
}); | ||
}); | ||
|
||
//so that we flesh out problems with maven publication during the build process | ||
project.getTasks().getByName("build").dependsOn(MAVEN_LOCAL_TASK); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...shipkit/src/main/resources/META-INF/gradle-plugins/org.shipkit.android-publish.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
implementation-class=org.shipkit.internal.gradle.android.AndroidPublishPlugin |
133 changes: 133 additions & 0 deletions
133
subprojects/shipkit/src/test/groovy/org/shipkit/gradle/ShipkitAndroidIntegTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.shipkit.gradle | ||
|
||
import org.gradle.testkit.runner.BuildResult | ||
import testutil.GradleSpecification | ||
|
||
class ShipkitAndroidIntegTest extends GradleSpecification { | ||
|
||
void setup() { | ||
settingsFile << "include 'lib'" | ||
newFile('lib/build.gradle') << """ | ||
apply plugin: 'org.shipkit.bintray' | ||
apply plugin: 'org.shipkit.android-publish' | ||
androidPublish { | ||
artifactId = 'shipkit-android' | ||
} | ||
apply plugin: 'com.android.library' | ||
android { | ||
compileSdkVersion 29 | ||
defaultConfig { | ||
minSdkVersion 29 | ||
} | ||
} | ||
""" | ||
|
||
newFile("gradle/shipkit.gradle") << """ | ||
shipkit { | ||
gitHub.readOnlyAuthToken = "foo" | ||
gitHub.writeAuthToken = "secret" | ||
releaseNotes.file = "CHANGELOG.md" | ||
git.user = "shipkit" | ||
git.email = "[email protected]" | ||
gitHub.repository = "repo" | ||
} | ||
allprojects { | ||
plugins.withId("com.jfrog.bintray") { | ||
bintray { | ||
user = "szczepiq" | ||
key = "secret" | ||
} | ||
} | ||
} | ||
""" | ||
buildFile << """ | ||
apply plugin: 'org.shipkit.java' | ||
buildscript { | ||
repositories { | ||
google() | ||
jcenter() | ||
gradlePluginPortal() | ||
} | ||
} | ||
""" | ||
newFile("src/main/AndroidManifest.xml") << """<manifest package="org.shipkit.android"/>""" | ||
} | ||
|
||
def "all tasks in dry run (gradle #gradleVersionToTest) (AGP #agpVersionToTest)"() { | ||
/** | ||
* TODO this test is just a starting point we will make it better and create more integration tests | ||
* Stuff that we should do: | ||
* 1. (Most important) Avoid writing too many integration tests. Most code should be covered by unit tests | ||
* (see testing pyramid) | ||
* 2. Push out complexity to base class GradleSpecification | ||
* so that what remains in the test is the essential part of a tested feature | ||
* 3. Add more specific assertions rather than just a list of tasks in dry run mode | ||
* 4. Use sensible defaults so that we don't need to specify all configuration in the test | ||
* 5. Move integration tests to a separate module | ||
* 6. Dependencies are hardcoded between GradleSpecification and build.gradle of release-tools project | ||
*/ | ||
given: | ||
gradleVersion = gradleVersionToTest | ||
and: | ||
buildFile << """ | ||
buildscript { | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:$agpVersionToTest' | ||
} | ||
} | ||
""" | ||
expect: | ||
BuildResult result = pass("performRelease", "-m", "-s") | ||
//git push and bintray upload tasks should run as late as possible | ||
def output = skippedTaskPathsGradleBugWorkaround(result.output).join("\n") | ||
output.startsWith(""":bumpVersionFile | ||
:identifyGitBranch | ||
:fetchContributors | ||
:fetchReleaseNotes | ||
:updateReleaseNotes | ||
:gitCommit | ||
:gitTag | ||
:gitPush | ||
:performGitPush | ||
:updateReleaseNotesOnGitHub | ||
:lib:preBuild""") | ||
and: | ||
output.endsWith(""":lib:bintrayUpload | ||
:bintrayPublish | ||
:performRelease""") | ||
where: | ||
gradleVersionToTest << ["5.6.4", "6.0.1"] | ||
and: | ||
agpVersionToTest << ["3.6.0-beta05", "3.6.0-rc01"] | ||
} | ||
def "fails on unsupported dependency versions (gradle #gradleVersionToTest) (AGP #agpVersionToTest)"() { | ||
given: | ||
gradleVersion = gradleVersionToTest | ||
and: | ||
buildFile << """ | ||
buildscript { | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:$agpVersionToTest' | ||
} | ||
} | ||
""" | ||
expect: | ||
BuildResult result = fail("performRelease", "-m", "-s") | ||
result.output.contains("'release' component not found in project. " + | ||
"Make sure you are using Android Gradle Plugin 3.6.0-beta05 or newer.") | ||
where: | ||
gradleVersionToTest << ["5.6.4", "6.0.1"] | ||
and: | ||
agpVersionToTest << ["3.4.0", "3.5.2"] | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...t/src/test/groovy/org/shipkit/gradle/configuration/AndroidPublishConfigurationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.shipkit.gradle.configuration | ||
|
||
import org.gradle.api.GradleException | ||
import spock.lang.Specification | ||
|
||
class AndroidPublishConfigurationTest extends Specification { | ||
|
||
def conf = new AndroidPublishConfiguration(); | ||
|
||
def "throws when artifact id not configured"() { | ||
when: | ||
conf.artifactId | ||
|
||
then: | ||
thrown(GradleException) | ||
} | ||
|
||
def "stores artifact id"() { | ||
when: | ||
conf.artifactId = "org.shipkit.android" | ||
|
||
then: | ||
conf.artifactId == "org.shipkit.android" | ||
} | ||
} |
Oops, something went wrong.