Skip to content
Closed
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
30 changes: 11 additions & 19 deletions gradle/published-java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,35 @@ var signingExtension = project.getExtensions().getByType(SigningExtension) as Si
signingExtension.sign publishing.publications.publishedArtifacts

gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
boolean wasSigningRequested = false
boolean wasPublishingRequested = false

graph.allTasks.each {task ->
if ( task instanceof Sign ) {
wasSigningRequested = true
}
else if ( task instanceof PublishToMavenRepository ) {
if ( task instanceof PublishToMavenRepository ) {
wasPublishingRequested = true
}
}

var signingKey = resolveSigningKey()
var signingPassword = resolveSigningPassphrase()

if ( wasPublishingRequested ) {
if ( signingKey == null || signingPassword == null ) {
throw new RuntimeException("Cannot perform signing without GPG details.")
}

def ossrhUser = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypeUsername" )
def ossrhPass = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypePassword" )
if ( ossrhUser == null || ossrhPass == null ) {
throw new RuntimeException( "Cannot perform publishing to OSSRH without credentials." )
}
logger.lifecycle "Publishing {} : {} : {}", project.group, project.name, project.version
}

if ( wasSigningRequested || wasPublishingRequested ) {
// signing was explicitly requested and/or we are publishing to Sonatype OSSRH
// - we need the signing to happen
signingExtension.required = true

var signingKey = resolveSigningKey()
var signingPassword = resolveSigningPassphrase()
signingExtension.useInMemoryPgpKeys( signingKey, signingPassword )
}
else {
// signing was not explicitly requested and we are not publishing to OSSRH,
// - disable all Sign tasks
else if ( signingKey == null || signingPassword == null ) {
tasks.withType( Sign ).each { t-> t.enabled = false }
}
}
Expand All @@ -171,15 +167,11 @@ static String resolveSigningKey() {
return new File( keyFile ).text
}

throw new RuntimeException( "Cannot perform signing without GPG details." )
return null
}

static String resolveSigningPassphrase() {
var passphrase = System.getenv().get( "SIGNING_GPG_PASSPHRASE" )
if ( passphrase == null ) {
throw new RuntimeException( "Cannot perform signing without GPG details." )
}
return passphrase
return System.getenv().get( "SIGNING_GPG_PASSPHRASE" )
}


Expand Down