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
workaround issues with the signing setup #404
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,11 @@ import org.gradle.api.credentials.PasswordCredentials | |
import org.gradle.api.provider.Property | ||
import org.gradle.api.publish.maven.MavenPom | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven | ||
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository | ||
import org.gradle.build.event.BuildEventsListenerRegistry | ||
import org.gradle.configurationcache.extensions.serviceOf | ||
import org.gradle.plugins.signing.Sign | ||
import org.gradle.plugins.signing.SigningPlugin | ||
|
||
@Incubating | ||
|
@@ -69,11 +72,9 @@ abstract class MavenPublishBaseExtension( | |
repo.credentials(PasswordCredentials::class.java) | ||
} | ||
|
||
project.gradlePublishing.publications.withType(MavenPublication::class.java).all { publication -> | ||
project.afterEvaluate { | ||
project.tasks.named("publish${publication.name.capitalize()}PublicationToMavenCentralRepository") { | ||
it.dependsOn(createRepository) | ||
} | ||
project.tasks.withType(PublishToMavenRepository::class.java).configureEach { publishTask -> | ||
if (publishTask.name.endsWith("ToMavenCentralRepository")) { | ||
publishTask.dependsOn(createRepository) | ||
} | ||
} | ||
|
||
|
@@ -114,14 +115,27 @@ abstract class MavenPublishBaseExtension( | |
|
||
project.plugins.apply(SigningPlugin::class.java) | ||
project.gradleSigning.setRequired(Callable { !project.versionIsSnapshot }) | ||
project.gradleSigning.sign(project.gradlePublishing.publications) | ||
|
||
val inMemoryKey = project.findOptionalProperty("signingInMemoryKey") | ||
if (inMemoryKey != null) { | ||
val inMemoryKeyId = project.findOptionalProperty("signingInMemoryKeyId") | ||
val inMemoryKeyPassword = project.findOptionalProperty("signingInMemoryKeyPassword") ?: "" | ||
project.gradleSigning.useInMemoryPgpKeys(inMemoryKeyId, inMemoryKey, inMemoryKeyPassword) | ||
} | ||
|
||
// TODO: replace with the following line after https://github.com/gradle/gradle/issues/21857 is fixed | ||
// project.gradleSigning.sign(project.gradlePublishing.publications) | ||
project.gradlePublishing.publications.withType(MavenPublication::class.java).all { publication -> | ||
val task = project.tasks.findByName("sign${publication.name.capitalize()}Publication") | ||
if (task == null) { | ||
project.gradleSigning.sign(publication) | ||
} | ||
} | ||
Comment on lines
+126
to
+133
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. Only call sign on a publication if there is no signing task for it yet which fixes the issue when other plugins already called it. |
||
|
||
// TODO: remove after https://youtrack.jetbrains.com/issue/KT-46466 is fixed | ||
project.tasks.withType(AbstractPublishToMaven::class.java) { publishTask -> | ||
publishTask.dependsOn(project.tasks.withType(Sign::class.java)) | ||
} | ||
Comment on lines
+135
to
+138
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. Workaround taken from the linked ticket |
||
} | ||
|
||
/** | ||
|
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.
Found out that
PublishToMavenRepository
is in the public API so we can use it here as a filter which makes it nicer than afterEvaluate