Skip to content

Commit

Permalink
Move from Maven to Gradle
Browse files Browse the repository at this point in the history
This is a minimized patch based on the work by @mrmcduff-stripe here:

#416
  • Loading branch information
brandur committed Oct 27, 2017
1 parent a624cd0 commit b241bb5
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 159 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,7 @@ tags
target
.idea
*.iml

# Gradle files
.gradle/*
build/*
11 changes: 9 additions & 2 deletions .travis.yml
@@ -1,17 +1,24 @@
language: java

addons:
hosts:
- short-hostname
hostname: short-hostname

matrix:
include:
- jdk: openjdk7
dist: precise
- jdk: oraclejdk7
dist: precise
- jdk: oraclejdk8
- jdk: oraclejdk9

install: mvn install -Dgpg.skip=true -DskipTests

notifications:
email:
on_success: never

sudo: false

script:
- ./gradlew clean test
13 changes: 6 additions & 7 deletions README.md
Expand Up @@ -103,16 +103,15 @@ servers.

## Testing

You must have Maven installed. To run the tests:
You must have Gradle installed. To run the tests:

mvn test
./gradlew test

You can run particular tests by passing `-D test=Class#method`. Make sure you use the fully qualified class name to differentiate between
unit and functional tests. For example:
You can run particular tests by passing `--tests Class#method`. Make sure you use the fully qualified class name. For example:

mvn test -D test=com.stripe.model.AccountTest
mvn test -D test=com.stripe.functional.ChargeTest
mvn test -D test=com.stripe.functional.ChargeTest#testChargeCreate
./gradlew test --tests com.stripe.model.AccountTest
./gradlew test --tests com.stripe.functional.ChargeTest
./gradlew test --tests com.stripe.functional.ChargeTest.testChargeCreate

<!--
# vim: set tw=79:
Expand Down
35 changes: 35 additions & 0 deletions build.gradle
@@ -0,0 +1,35 @@
apply plugin: 'java'
apply plugin: 'maven'

sourceCompatibility = 1.7
targetCompatibility = 1.7
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

configurations.all {
}

buildscript {
repositories {
jcenter()
//Add only for SNAPSHOT versions
//maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0"
}
}

repositories {
jcenter()
}

dependencies {
compile group: 'com.google.code.gson', name: 'gson', version:'2.2.4'
testCompile group: 'com.google.guava', name: 'guava', version:'18.0'
testCompile group: 'junit', name: 'junit', version:'4.10'
testCompile group: 'org.mockito', name: 'mockito-all', version:'1.10.19'
}

apply from: 'deploy.gradle'
121 changes: 121 additions & 0 deletions deploy.gradle
@@ -0,0 +1,121 @@
/*
* Based on the example at Chris Banes's repository that allows signing
* without manually creating a maven file.
*
* The original can be found at
* https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle
*/

apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'io.codearte.nexus-staging'

nexusStaging {
packageGroup = GROUP
}

def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}

def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}

snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}

pom.project {
name POM_NAME
description POM_DESCRIPTION
url POM_URL
packaging POM_PACKAGING

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
email POM_DEVELOPER_EMAIL
}
}

organization {
name POM_DEVELOPER_NAME
url POM_ORGANIZATION_URL
}
}
}
}
}

signing {
required { isReleaseBuild() &&
(gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))}
sign configurations.archives
}

task makeJavadocs(type: Javadoc) {
source = sourceSets.main.allJava
classpath = configurations.compile
failOnError = true
}

task makeJavadocsJar(type: Jar, dependsOn: makeJavadocs) {
classifier = 'javadoc'
from makeJavadocs.destinationDir
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.java
}

artifacts {
archives jar
archives sourcesJar
archives makeJavadocsJar
}
}
19 changes: 19 additions & 0 deletions gradle.properties
@@ -0,0 +1,19 @@
GROUP=com.stripe
VERSION_NAME=5.22.0

POM_URL=https://github.com/stripe/stripe-java
POM_SCM_URL=git@github.com:stripe/stripe-java.git
POM_SCM_CONNECTION=scm:git:git@github.com:stripe/stripe-java.git
POM_SCM_DEV_CONNECTION=scm:git:git@github.com:stripe/stripe-java.git
POM_LICENCE_NAME=The MIT License
POM_LICENCE_URL=https://opensource.org/licenses/MIT
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=stripe
POM_DEVELOPER_NAME=Stripe
POM_DEVELOPER_EMAIL=support+java@stripe.com

POM_DESCRIPTION=Stripe Java Bindings
POM_NAME=stripe-java
POM_ARTIFACT_ID=stripe-java
POM_PACKAGING=jar
POM_ORGANIZATION_URL=https://stripe.com
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip

0 comments on commit b241bb5

Please sign in to comment.