Navigation Menu

Skip to content

Commit

Permalink
#24: Add OSS sonatype publishing script for publishing test snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
heshamMassoud committed Aug 28, 2017
1 parent 4def38f commit cf454e3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
18 changes: 18 additions & 0 deletions BUILD.md
Expand Up @@ -61,6 +61,24 @@ where `publishToMavenLocal` is a task from
[`maven-publish`](https://docs.gradle.org/3.3/userguide/publishing_maven.html#publishing_maven:install)
plugin.

## Publish snapshots to oss.sonatype.org

To publish to [OSS Sonatype snapshots](https://oss.sonatype.org/content/repositories/snapshots/com/commercetools/)
repo the following command is used:

```bash
./gradlew clean build uploadArchives -Dbuild.version=X.X.X-SNAPSHOT
```

The `-SNAPSHOT` suffix is mandatory.

**Note**: for publishing to OSS Sonatype you need specify **API** User/Key (not login credentials) for
`OSS_USER`/`OSS_KEY` environment variables or `ossUser`/`ossKey` gradle build properties
(the properties have precedence over environment variables).

See more configuration details of the oss uploading in [oss-publish.gradle](./gradle-scripts/oss-publish.gradle) file.


## Publish to Bintray

[Bintray documentation about publish process](https://blog.bintray.com/2014/02/11/bintray-as-pain-free-gateway-to-maven-central/)
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -28,4 +28,5 @@ apply from: "$rootDir/gradle-scripts/jacoco.gradle"
apply from: "$rootDir/gradle-scripts/findbugs.gradle"
apply from: "$rootDir/gradle-scripts/maven-publish.gradle"
apply from: "$rootDir/gradle-scripts/bintray-publish.gradle"
apply from: "$rootDir/gradle-scripts/oss-publish.gradle"
apply from: "$rootDir/gradle-scripts/javadocs-publish.gradle"
64 changes: 64 additions & 0 deletions gradle-scripts/oss-publish.gradle
@@ -0,0 +1,64 @@
// OSS SONATYPE SNAPSHOTS upload configuration
final snapshotsRepository = 'https://oss.sonatype.org/content/repositories/snapshots/'

uploadArchives {
doFirst {
logger.info("Verifying OSS SONATYPE credentials:")
def authentication = repositories.mavenDeployer.snapshotRepository.authentication
if (!(authentication.userName?.trim() && authentication.password?.trim())) {
throw new InvalidUserDataException('OSS SONATYPE User or API Key is not set. Please ensure one of the ' +
"following is set:" +
"1. OSS_USER and OSS_KEY environment variables.\n" +
"2. -DossUser and -DossKey java runtime properties.\n" +
"3. ossUser and ossKey properties in gradle.properties file.")
}

validateSnapshotVersion("Publishing to OSS SONATYPE can only be performed for $SNAPSHOT versions")
}

repositories {
mavenDeployer {
snapshotRepository(url: snapshotsRepository) {
authentication(
userName: rootProject.hasProperty('ossUser') ? rootProject.property('ossUser') : System.getenv('OSS_USER'),
password: rootProject.hasProperty('ossKey') ? rootProject.property('ossKey') : System.getenv('OSS_KEY')
)
}

pom.project {
name rootProject.name

url scmProjectUrl
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
scm {
connection "scm:git:$scmHttpsUrl"
developerConnection "scm:git:$scmSshUrl"
url "$scmProjectUrl"
}
developers {
developer {
id 'heshamMassoud'
name 'Hesham Massoud'
url 'https://github.com/heshamMassoud'
email 'hesham.massoud@commercetools.com'
}
}
}
}
}
}

void validateSnapshotVersion(String prefix) throws InvalidUserDataException {
// validate version has snapshot suffix to publish it to oss sonatype
if (!(rootProject.version?.trim() && rootProject.version.endsWith(SNAPSHOT_SUFFIX))) {
throw new InvalidUserDataException(
"$prefix.\nPlease, specify -Dbuild.version=<version-name>$SNAPSHOT_SUFFIX as the build argument.\n" +
"Current version is \"$rootProject.version\"")
}
}
2 changes: 2 additions & 0 deletions gradle.properties.skeleton
@@ -1,3 +1,5 @@
ossUser=<<please ask support for OSS credentials>>
ossKey=<<please ask support for OSS credentials>>
bintrayUser=<<please ask support for bintray credentials>>
bintrayKey=<<please ask support for bintray credentials>>
org.ajoberstar.grgit.auth.username=<<github token to publish javadoc>>

0 comments on commit cf454e3

Please sign in to comment.