diff --git a/build.gradle b/build.gradle index c92e67e5..d318fa64 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,10 @@ -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'signing' -apply plugin: 'checkstyle' +plugins{ + id 'java-library' + id 'signing' + id 'checkstyle' + id 'maven-publish' +} + group 'io.github.jopenlibs' archivesBaseName = 'vault-java-driver' @@ -16,16 +19,16 @@ repositories { } dependencies { - testCompile('junit:junit:4.13.2') - testCompile('org.mockito:mockito-core:4.8.0') - testCompile('org.testcontainers:testcontainers:1.17.5') - testCompile('org.eclipse.jetty:jetty-server:11.0.12') - testCompile('org.slf4j:slf4j-api:2.0.3') - testCompile('org.bouncycastle:bcprov-jdk15on:1.70') - testCompile('org.bouncycastle:bcpkix-jdk15on:1.70') - testCompile('org.apache.commons:commons-io:1.3.2') - - testRuntime('org.slf4j:slf4j-simple:2.0.3') + testImplementation('junit:junit:4.13.2') + testImplementation('org.mockito:mockito-core:4.8.0') + testImplementation('org.testcontainers:testcontainers:1.17.5') + testImplementation('org.eclipse.jetty:jetty-server:11.0.12') + testImplementation('org.slf4j:slf4j-api:2.0.3') + testImplementation('org.bouncycastle:bcprov-jdk15on:1.70') + testImplementation('org.bouncycastle:bcpkix-jdk15on:1.70') + testImplementation('org.apache.commons:commons-io:1.3.2') + + testRuntimeOnly('org.slf4j:slf4j-simple:2.0.3') } // Beginning of Java 9 compatibility config @@ -46,10 +49,11 @@ compileJava { options.compilerArgs = ['--release', '8'] } -compileJava.options.encoding = 'UTF-8' -compileTestJava.options.encoding = 'UTF-8' +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' +} -task compileModuleInfoJava(type: JavaCompile) { +tasks.register('compileModuleInfoJava', JavaCompile) { classpath = files() source = 'src/main/java/module-info.java' destinationDir = compileJava.destinationDir @@ -67,27 +71,21 @@ compileModuleInfoJava.dependsOn compileJava classes.dependsOn compileModuleInfoJava // End of Java 9 compatibility config -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' +tasks.register('javadocJar', Jar) { + dependsOn tasks.named("javadoc") + archiveClassifier.set('javadoc') from javadoc.destinationDir } -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' +tasks.register('sourcesJar', Jar) { + dependsOn tasks.named("classes") + archiveClassifier.set('sources') from sourceSets.main.allSource } // // Separate unit tests from integration tests. See: `src/test-integration/README.md` // - -configurations { - unitTestsCompile.extendsFrom testCompile - unitTestsRuntime.extendsFrom testRuntime - integrationTestsCompile.extendsFrom testCompile - integrationTestsRuntime.extendsFrom testRuntime -} - sourceSets { unitTests { compileClasspath += main.output + test.output @@ -102,7 +100,15 @@ sourceSets { } } -task unitTest(type: Test) { +configurations { + unitTestsImplementation.extendsFrom testImplementation + unitTestsRuntimeOnly.extendsFrom testRuntimeOnly + integrationTestsImplementation.extendsFrom testImplementation + integrationTestsRuntimeOnly.extendsFrom testRuntimeOnly +} + +tasks.named('test') { + useJUnit() testClassesDirs = sourceSets.unitTests.output.classesDirs classpath = sourceSets.unitTests.runtimeClasspath testLogging { @@ -113,7 +119,8 @@ task unitTest(type: Test) { reports.junitXml.enabled = true } -task integrationTest(type: Test) { +def integrationTestTask = tasks.register('integrationTest', Test) { + useJUnit() testClassesDirs = sourceSets.integrationTests.output.classesDirs classpath = sourceSets.integrationTests.runtimeClasspath testLogging { @@ -145,74 +152,84 @@ artifacts { } if (hasProperty("publish")) { - signing { - sign configurations.archives - } - - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: ossrhUsername, password: ossrhPassword) - } + publishing { + publications { + mavenJava(MavenPublication) { + artifactId = 'vault-java-driver' + from components.java - pom.project { - name 'vault-java-driver' - packaging 'jar' - // optionally artifactId can be defined here - description 'Zero-dependency Java client for HashiCorp\'s Vault' - url 'https://github.com/jopenlibs/vault-java-driver' + pom { + name = 'vault-java-driver' + packaging = 'jar' + description = 'Zero-dependency Java client for HashiCorp\'s Vault' + url = 'https://github.com/jopenlibs/vault-java-driver' scm { - connection 'https://github.com/jopenlibs/vault-java-driver.git' - developerConnection 'https://github.com/jopenlibs/vault-java-driver.git' - url 'https://github.com/jopenlibs/vault-java-driver' + connection = 'https://github.com/jopenlibs/vault-java-driver.git' + developerConnection = 'https://github.com/jopenlibs/vault-java-driver.git' + url = 'https://github.com/jopenlibs/vault-java-driver' } licenses { license { - name 'MIT' - url 'https://github.com/jopenlibs/vault-java-driver/blob/master/README.md#license' + name = 'MIT' + url = 'https://github.com/jopenlibs/vault-java-driver/blob/master/README.md#license' } } developers { [ - developer { - id 'steve-perkins' - name 'Steve Perkins' - email 'steve@steveperkins.com' - }, - developer { - id 'steve-perkins-bc' - name 'Steve Perkins' - email 'steve.perkins@bettercloud.com' - }, - developer { - id 'jarrodcodes' - name 'Jarrod Young' - email 'jarrodsy@gmail.com' - }, - developer { - id 'tledkov' - name 'Taras Ledkov' - email 'tledkov@apache.org' - }, - developer { - id 'henryx' - name 'Enrico Bianchi' - email 'enrico.bianchi@gmail.com' - } + developer { + id = 'steve-perkins' + name = 'Steve Perkins' + email = 'steve@steveperkins.com' + }, + developer { + id = 'steve-perkins-bc' + name = 'Steve Perkins' + email = 'steve.perkins@bettercloud.com' + }, + developer { + id = 'jarrodcodes' + name = 'Jarrod Young' + email = 'jarrodsy@gmail.com' + }, + developer { + id = 'tledkov' + name = 'Taras Ledkov' + email = 'tledkov@apache.org' + }, + developer { + id = 'henryx' + name = 'Enrico Bianchi' + email = 'enrico.bianchi@gmail.com' + } ] } } } } + repositories { + maven { + credentials { + username "$ossrhUsername" + password "$ossrhPassword" + } + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + } + } + } + + signing { + sign publishing.publications.mavenJava + } + + javadoc { + if(JavaVersion.current().isJava9Compatible()) { + options.addBooleanOption('html5', true) + } } }