Last active
August 8, 2018 23:32
-
-
Save nipafx/d1850ac402f086e1b4fc42f58f5aa365 to your computer and use it in GitHub Desktop.
Publish project snapshots to Sonatype's snapshot repo with Gradle's maven-publish Plugin
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 is the Gist for a post I wrote about publishing snapshots with Gradle's maven-publish plugin: | |
// http://blog.codefx.org/tools/snapshots-gradle-maven-publish-plugin | |
// PROJECT_NAME is defined in settings.gradle | |
group 'PROJECT_GROUP' | |
version 'PROJECT_VERSION' | |
apply plugin: 'java' | |
apply plugin: 'maven-publish' | |
ext { | |
// the password needs to be specified via command line with -P | |
snapshotRepoPass = project.hasProperty('snapshotRepoPass') ? project.getProperty('snapshotRepoPass') : '' | |
} | |
publishing { | |
publications { | |
mavenJava(MavenPublication) { | |
from components.java | |
artifact sourceJar | |
artifact javadocJar | |
pom.withXml { | |
asNode().with { | |
appendNode('packaging', 'jar') | |
appendNode('name', 'PROJECT_NAME') | |
appendNode('description', 'PROJECT_DESCRIPTION') | |
appendNode('url', 'PROJECT_URL') | |
appendNode('scm').with { | |
appendNode('url', 'SCM_URL_FOR_PEOPLE') | |
appendNode('connection', 'SCM_URL_FOR_SCM') | |
} | |
appendNode('issueManagement').with { | |
appendNode('url', 'ISSUE_TRACKER_URL') | |
appendNode('system', 'ISSUE_TRACKER_NAME') | |
} | |
appendNode('licenses').with { | |
appendNode('license').with { | |
appendNode('name', 'LICENSE_NAME') | |
appendNode('url', 'LICENSE_URL') | |
} | |
} | |
appendNode('organization').with { | |
appendNode('name', 'ORG_NAME') | |
appendNode('url', 'ORG_URL') | |
} | |
appendNode('developers').with { | |
appendNode('developer').with { | |
appendNode('id', 'DEV_HANDLE') | |
appendNode('name', 'DEV_NAME') | |
appendNode('email', 'DEV_MAIL') | |
appendNode('organization', 'ORG_NAME_AGAIN') | |
appendNode('organizationUrl', 'ORG_URL_AGAIN') | |
appendNode('timezone', 'UTC_OFFSET') | |
} | |
} | |
} | |
} | |
tasks.withType(Jar) { | |
from(project.projectDir) { | |
include 'LICENSE.md' | |
into 'META-INF' | |
} | |
} | |
} | |
} | |
repositories { | |
maven { | |
url 'https://oss.sonatype.org/content/repositories/snapshots/' | |
credentials { | |
username "nipa" | |
password project.snapshotRepoPass | |
} | |
} | |
} | |
} | |
task sourceJar(type: Jar, dependsOn: classes) { | |
classifier 'sources' | |
from sourceSets.main.allSource | |
} | |
task javadocJar(type: Jar, dependsOn: javadoc) { | |
classifier = 'javadoc' | |
from javadoc.destinationDir | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment