-
Notifications
You must be signed in to change notification settings - Fork 9
Use convention plugins instead of script plugins #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6c21cca
feat: Create a few projects for pugins in includedBuild
jmatsu 7102a97
feat: Create a plugin for sdk and publishing it
jmatsu b831946
refactor: Reformat code and use some extensions
jmatsu 4642a28
fix: JDK 1.7 is correct for sdk modules
jmatsu 36ccf50
fix: Set target sdk in a library module to use it in unit testing
jmatsu c0054c8
chore: Add a script to verify publications and run it on PRs
jmatsu b4f6b46
chore: Pass --no-daemon when building projects on CI
jmatsu f51681d
chore: stop gradle daemon anyway
jmatsu e90c3d1
chore: Set GRADLE_OPTS to configure jvm args
jmatsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,36 +1,10 @@ | ||
| // Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
| ext { | ||
| // sdk/java/com/deploygate/sdk/HostAppTest.java needs to be changed for a new release | ||
| releaseVersion = '4.7.1' | ||
| } | ||
|
|
||
| buildscript { | ||
| repositories { | ||
| mavenCentral() | ||
| google() | ||
| gradlePluginPortal() | ||
| } | ||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:7.4.2' | ||
| classpath 'com.project.starter:easylauncher:5.0.1' | ||
| } | ||
| } | ||
|
|
||
| allprojects { | ||
| repositories { | ||
| mavenCentral() | ||
| google() | ||
| } | ||
| plugins { | ||
| id("com.deploygate.plugins.sdk") apply false | ||
| id("com.deploygate.plugins.sample-app") apply false | ||
| } | ||
|
|
||
| task clean(type: Delete) { | ||
| delete rootProject.buildDir | ||
| } | ||
|
|
||
| task verifyReleaseVersion() { | ||
| doLast { | ||
| if (project.ext.releaseVersion != System.getenv("RELEASE_VERSION")) { | ||
| throw new GradleException("${project.ext.releaseVersion} does not equal to ${System.getenv("RELEASE_VERSION")}") | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| android.useAndroidX=true | ||
| android.useAndroidX=true | ||
| android.disableAutomaticComponentCreation=true | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default from AGP8. Currently, it's 7. |
||
This file contains hidden or 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,7 @@ | ||
| plugins { | ||
| `kotlin-dsl` apply false | ||
| } | ||
|
|
||
| tasks.register("clean", Delete::class) { | ||
| delete(rootProject.buildDir) | ||
| } |
This file contains hidden or 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,17 @@ | ||
| plugins { | ||
| `kotlin-dsl` | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22") | ||
| implementation("com.android.tools.build:gradle:7.4.2") | ||
| } | ||
|
|
||
| gradlePlugin { | ||
| plugins { | ||
| create("sdk") { | ||
| id = "com.deploygate.plugins.sdk" | ||
| implementationClass = "com.deploygate.plugins.SdkPlugin" | ||
| } | ||
| } | ||
| } |
162 changes: 162 additions & 0 deletions
162
plugins/library/src/main/java/com/deploygate/plugins/MavenPublishPlugin.kt
This file contains hidden or 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,162 @@ | ||
| package com.deploygate.plugins | ||
|
|
||
| import com.deploygate.plugins.ext.internalApiLibraryExtension | ||
| import com.deploygate.plugins.ext.publishingExtension | ||
| import com.deploygate.plugins.ext.sdkExtension | ||
| import com.deploygate.plugins.ext.signingExtension | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.repositories.PasswordCredentials | ||
| import org.gradle.api.publish.PublicationContainer | ||
| import org.gradle.api.publish.PublishingExtension | ||
| import org.gradle.api.publish.maven.MavenPublication | ||
| import org.gradle.api.tasks.Exec | ||
| import org.gradle.kotlin.dsl.apply | ||
| import org.gradle.kotlin.dsl.create | ||
| import org.gradle.kotlin.dsl.getByType | ||
| import org.gradle.kotlin.dsl.named | ||
| import org.gradle.kotlin.dsl.register | ||
| import org.gradle.plugins.signing.SigningExtension | ||
| import java.util.Locale | ||
|
|
||
| class MavenPublishPlugin : Plugin<Project> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from |
||
| companion object { | ||
| private val RELEASE_VERSION_REGEX = "^\\d+\\.\\d+\\.\\d+\$".toRegex() | ||
| } | ||
|
|
||
| override fun apply(target: Project) { | ||
| target.apply(plugin = "maven-publish") | ||
| target.apply(plugin = "signing") | ||
|
|
||
| val artifactVersion = target.version as String | ||
|
|
||
| val repositoryUsername = target.findProperty("NEXUS_USERNAME") as? String | ||
| val repositoryPassword = target.findProperty("NEXUS_PASSWORD") as? String | ||
| val signingKey = target.findProperty("signingKey") as? String | ||
| val signingPassword = target.findProperty("signingPassword") as? String | ||
|
|
||
| val isRelease = artifactVersion.matches(RELEASE_VERSION_REGEX) | ||
|
|
||
| target.internalApiLibraryExtension.libraryVariants.configureEach { | ||
| val variant = this | ||
|
|
||
| target.tasks.register<Exec>("verifyBytecodeVersion${variant.name.capitalize(Locale.ROOT)}") | ||
| .configure { | ||
| dependsOn(variant.assembleProvider) | ||
|
|
||
| commandLine( | ||
| target.rootProject.file("scripts/verify-bytecode-version"), | ||
| "--aar", | ||
| variant.packageLibraryProvider.flatMap { it.archiveFile }.get(), | ||
| "--java", | ||
| SdkPlugin.JAVA_VERSION.toString() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| target.publishingExtension.configurePublishingExtension( | ||
| target = target, | ||
| artifactVersion = artifactVersion, | ||
| isRelease = isRelease, | ||
| repositoryUsername = repositoryUsername, | ||
| repositoryPassword = repositoryPassword, | ||
| ) | ||
| target.signingExtension.configureSigningExtension( | ||
| isSigningRequired = isRelease, | ||
| signingKey = signingKey, | ||
| signingPassword = signingPassword, | ||
| publications = target.extensions.getByType<PublishingExtension>().publications, | ||
| ) | ||
|
|
||
| target.gradle.taskGraph.whenReady { | ||
| with(target.signingExtension) { | ||
| isRequired = isRequired && hasTask("publishReleasePublicationToMavenRepository") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun PublishingExtension.configurePublishingExtension( | ||
| target: Project, | ||
| artifactVersion: String, | ||
| isRelease: Boolean, | ||
| repositoryUsername: String?, | ||
| repositoryPassword: String?, | ||
| ) { | ||
| repositories { | ||
| maven { | ||
| setUrl( | ||
| if (isRelease) { | ||
| "https://oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
| } else { | ||
| "https://oss.sonatype.org/content/repositories/snapshots/" | ||
| } | ||
| ) | ||
|
|
||
| credentials(PasswordCredentials::class.java) { | ||
| username = repositoryUsername | ||
| password = repositoryPassword | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| publications { | ||
| create<MavenPublication>("release") { | ||
| // This block would be evaluated before components.getByName("release") was created | ||
|
|
||
| groupId = "com.deploygate" | ||
| version = artifactVersion | ||
|
|
||
| pom { | ||
| name.set(target.sdkExtension.displayName) | ||
| description.set(target.sdkExtension.description) | ||
| url.set("https://github.com/DeployGate/deploygate-android-sdk") | ||
|
|
||
| licenses { | ||
| license { | ||
| name.set("The Apache Software License, Version 2.0") | ||
| url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
| distribution.set("repo") | ||
| } | ||
| } | ||
|
|
||
| developers { | ||
| developer { | ||
| id.set("deploygate") | ||
| name.set("DeployGate") | ||
| } | ||
| } | ||
|
|
||
| scm { | ||
| url.set("https://github.com/DeployGate/deploygate-android-sdk") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| target.afterEvaluate { | ||
| publications { | ||
| // Configure some values after AGP has been configured | ||
| named<MavenPublication>("release") { | ||
| from(components.getByName("release")) | ||
| artifactId = sdkExtension.artifactId.get() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private fun SigningExtension.configureSigningExtension( | ||
| isSigningRequired: Boolean, | ||
| signingKey: String?, | ||
| signingPassword: String?, | ||
| publications: PublicationContainer, | ||
| ) { | ||
| isRequired = isSigningRequired | ||
| useInMemoryPgpKeys(signingKey, signingPassword) | ||
|
|
||
| publications.configureEach { | ||
| sign(this) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same verifications will be done in the
build-sdkjob above.