Skip to content

feat: publish插件支持多项目 #193 #194

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 1 commit into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ class DevOpsPublishPlugin : Plugin<Project> {
isReleaseVersion = !project.version.toString().endsWith("SNAPSHOT")
project.pluginManager.apply(MavenPublishPlugin::class.java)
project.pluginManager.apply(SigningPlugin::class.java)
project.pluginManager.apply(NexusPublishPlugin::class.java)
configurePublishing(project)
configureSigning(project)
configureManifest(project)
if (project.rootProject == project) {
project.pluginManager.apply(NexusPublishPlugin::class.java)
configureNexusPublish(project)
}
project.afterEvaluate {
configurePublishing(project)
configureSigning(project)
configureManifest(project)
}
}

/**
Expand Down Expand Up @@ -61,6 +66,11 @@ class DevOpsPublishPlugin : Plugin<Project> {
}
}
}
}
}

private fun configureNexusPublish(project: Project) {
project.run {
extensions.getByType(NexusPublishExtension::class.java).repositories.sonatype { repo ->
val releaseUrl = findProperty(project, RELEASE_REPO_URL)
val snapshotUrl = findProperty(project, SNAPSHOT_REPO_URL)
Expand All @@ -77,21 +87,19 @@ class DevOpsPublishPlugin : Plugin<Project> {
*/
private fun configureSigning(project: Project) {
project.run {
afterEvaluate {
extensions.getByType(SigningExtension::class.java).run {
val signingKey = findProperty(project, SIGNING_KEY)
val signingKeyFile = findProperty(project, SIGNING_KEY_FILE)
val signingKeyId = findProperty(project, SIGNING_KEY_ID)
val signingPassword = findProperty(project, SIGNING_PASSWORD)
val secretKey: String? = signingKey ?: signingKeyFile?.let { File(it).readText() }
useInMemoryPgpKeys(signingKeyId, secretKey, signingPassword)
this.setRequired({ isReleaseVersion && gradle.taskGraph.hasTask(PUBLISH_TASK_PATH) })
sign(extensions.getByType(PublishingExtension::class.java).publications)
}
extensions.getByType(SigningExtension::class.java).run {
val signingKey = findProperty(project, SIGNING_KEY)
val signingKeyFile = findProperty(project, SIGNING_KEY_FILE)
val signingKeyId = findProperty(project, SIGNING_KEY_ID)
val signingPassword = findProperty(project, SIGNING_PASSWORD)
val secretKey: String? = signingKey ?: signingKeyFile?.let { File(it).readText() }
useInMemoryPgpKeys(signingKeyId, secretKey, signingPassword)
this.setRequired({ isReleaseVersion && tasks.findByName(PUBLISH_TASK_PATH) != null })
sign(extensions.getByType(PublishingExtension::class.java).publications)
}

tasks.withType(Sign::class.java) {
it.onlyIf { isReleaseVersion }
}
tasks.withType(Sign::class.java) {
it.onlyIf { isReleaseVersion }
}
}
}
Expand All @@ -101,14 +109,12 @@ class DevOpsPublishPlugin : Plugin<Project> {
*/
private fun configureManifest(project: Project) {
project.run {
afterEvaluate {
val manifestMap = mapOf(
"Implementation-Title" to (project.description ?: project.name),
"Implementation-Version" to project.version,
)
tasks.withType(Jar::class.java) {
it.manifest { manifest -> manifest.attributes(manifestMap) }
}
val manifestMap = mapOf(
"Implementation-Title" to (project.description ?: project.name),
"Implementation-Version" to project.version,
)
tasks.withType(Jar::class.java) {
it.manifest { manifest -> manifest.attributes(manifestMap) }
}
}
}
Expand Down