Skip to content

Commit 123d80f

Browse files
Applied several suggestions by Cédric Champeau (vavr-io#2644) (vavr-io#2665)
1 parent 4fcb945 commit 123d80f

File tree

3 files changed

+108
-97
lines changed

3 files changed

+108
-97
lines changed

.travis.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ env:
1515
matrix:
1616
include:
1717
- jdk: oraclejdk8
18+
env: JAVA_VERSION=8
1819
- jdk: openjdk11
19-
env: DEPLOY=true
20-
- jdk: openjdk14
21-
- jdk: openjdk-ea
22-
allow_failures:
23-
- jdk: openjdk-ea
20+
env: JAVA_VERSION=11 DEPLOY=true
21+
- jdk: openjdk16
22+
env: JAVA_VERSION=16
2423

2524
before_cache:
2625
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

build.gradle

+103-91
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,73 @@
55
* -> test reports: ./build/reports/tests/test/index.html
66
* -> coverage reports: ./build/reports/jacoco/test/html/index.html
77
* -> javadoc: `./build/docs/javadoc`
8-
*
8+
*
99
* - Release: `./gradlew release --info`
10+
*
11+
* - Release:
12+
* -> checking the generated artifacts: `./gradlew publishAllPublicationsToTestRepo` then look into `build/repo`
13+
* -> Releasing: `./gradlew release --info`
14+
*
15+
* In order to perform a release you need to:
16+
* - Add the following properties to ~/.gradle/gradle.properties
17+
* ossrhUsername=<username>
18+
* ossrhPassword=<password>
19+
* - or pass the credentials as command line parameters
20+
* ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -DossrhUsername=<my-username> -DossrhPassword=<my-password>
21+
*
22+
* And for signing the artifacts:
23+
* - Get public key ID `gpg --list-keys --keyid-format SHORT`
24+
* - Export key `gpg --keyring secring.gpg --export-secret-keys > ~/.gnupg/secring.gpg`
25+
* - Add the following properties to ~/.gradle/gradle.properties
26+
* signing.keyId=0ABCDEF
27+
* signing.password=password
28+
* signing.secretKeyRingFile=/absolute/path/to/.gnupg/secring.gpg
1029
*/
1130
plugins {
12-
id "net.researchgate.release" version "2.8.1"
13-
}
1431

15-
apply plugin: 'idea'
16-
apply plugin: 'java'
17-
apply plugin: 'jacoco'
18-
apply plugin: 'maven'
19-
apply plugin: 'signing'
32+
// library
33+
id 'java-library'
34+
id 'jacoco'
35+
36+
// publishing
37+
id 'maven-publish'
38+
id 'signing'
39+
id 'net.researchgate.release' version '2.8.1'
40+
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0'
41+
}
2042

21-
ext.ammoniteScalaVersion = '2.13' // Currently, generator/Generator.sc does not build with Scala 2.13
22-
ext.ammoniteVersion = '2.0.4'
43+
ext.ammoniteScalaVersion = '2.13'
44+
ext.ammoniteVersion = '2.3.8'
2345
ext.assertjVersion = '3.19.0'
24-
ext.junitVersion = '4.13'
46+
ext.junitVersion = '4.13.2'
47+
48+
// JAVA_VERSION used for CI build matrix, may be provided as env variable
49+
def javaVersion = Integer.parseInt(System.getenv('JAVA_VERSION') ?: '8')
2550

2651
repositories {
27-
mavenLocal()
2852
mavenCentral()
2953
}
3054

31-
sourceSets {
32-
main {
33-
java {
34-
srcDirs = ['src/main/java', 'src-gen/main/java']
35-
}
36-
}
37-
test {
38-
java {
39-
srcDirs = ['src/test/java', 'src-gen/test/java']
40-
}
55+
// -- --
56+
// -- JAVA BUILD & CODE GEN --
57+
// -- --
58+
59+
dependencies {
60+
testImplementation "junit:junit:$junitVersion"
61+
testImplementation "org.assertj:assertj-core:$assertjVersion"
62+
}
63+
64+
java {
65+
toolchain {
66+
languageVersion.set(JavaLanguageVersion.of(javaVersion))
4167
}
68+
withSourcesJar()
69+
withJavadocJar()
4270
}
4371

72+
sourceSets.main.java.srcDirs += ['src-gen/main/java']
73+
sourceSets.test.java.srcDirs += ['src-gen/test/java']
74+
4475
task generateSources() {
4576
doLast {
4677
delete 'src-gen'
@@ -62,103 +93,63 @@ task generateSources() {
6293

6394
compileJava.dependsOn 'generateSources'
6495

65-
tasks.withType(JavaCompile) {
66-
sourceCompatibility = 8
67-
targetCompatibility = 8
96+
tasks.withType(JavaCompile).configureEach {
6897
options.encoding = 'UTF-8'
6998
options.compilerArgs = [ '-Werror', '-Xlint:all', '-Xlint:-deprecation' ]
7099
}
71100

72-
dependencies {
73-
testImplementation "junit:junit:$junitVersion"
74-
testImplementation "org.assertj:assertj-core:$assertjVersion"
75-
}
76-
77-
jacocoTestReport {
101+
tasks.named('jacocoTestReport') {
78102
reports {
79103
xml.enabled = true
80104
}
81105
}
82106

83-
check {
107+
tasks.named('check') {
84108
dependsOn jacocoTestReport
85109
dependsOn javadoc
86110
}
87111

88-
jar {
112+
tasks.named('jar') {
89113
manifest {
90114
attributes('Automatic-Module-Name': 'io.vavr')
91115
}
92116
}
93117

94-
task sourcesJar(type: Jar) {
95-
from sourceSets.main.allSource
96-
archiveClassifier = 'sources'
97-
}
98-
99-
task testSourcesJar(type: Jar) {
118+
tasks.register('testSourcesJar', Jar) {
100119
from sourceSets.test.allSource
101120
archiveClassifier = 'test-sources'
102121
}
103122

104-
task javadocJar(type: Jar) {
105-
from javadoc
106-
archiveClassifier = 'javadoc'
107-
}
123+
// -- --
124+
// -- PUBLISHING & RELEASING --
125+
// -- --
108126

109-
artifacts {
110-
archives javadocJar, sourcesJar, testSourcesJar
111-
}
112-
113-
// Requirements:
114-
//
115-
// - Get public key ID `gpg --list-keys --keyid-format SHORT`
116-
// - Export key `gpg --keyring secring.gpg --export-secret-keys > ~/.gnupg/secring.gpg`
117-
// - Add the following properties to ~/.gradle/gradle.properties
118-
// signing.keyId=0ABCDEF
119-
// signing.password=password
120-
// signing.secretKeyRingFile=/absolute/path/to/.gnupg/secring.gpg
121-
//
122-
signing {
123-
required { !version.endsWith("-SNAPSHOT") }
124-
sign configurations.archives
125-
}
126-
127-
// Requirements:
128-
//
129-
// - Add the following properties to ~/.gradle/gradle.properties
130-
// ossrhUsername=<username>
131-
// ossrhPassword=<password>
132-
// - Or pass the credentials as command line parameters
133-
// ./gradlew uploadArchives -PossrhUsername=<my-username> -PossrhPassword=<my-password>
134-
//
135-
uploadArchives {
127+
// What we want to publish
128+
publishing {
136129
repositories {
137-
mavenDeployer {
138-
139-
def sonatypeUser = findProperty("ossrhUsername")
140-
def sonatypePass = findProperty("ossrhPassword")
141-
142-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
143-
144-
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
145-
authentication(userName: sonatypeUser, password: sonatypePass)
146-
}
147-
148-
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
149-
authentication(userName: sonatypeUser, password: sonatypePass)
150-
}
130+
maven {
131+
// A test repository which can be used to
132+
// verify what is going to be uploaded by
133+
// running ./gradlew publishAllPublicationsToTestRepo
134+
name = "testRepo"
135+
url = "${buildDir}/repo"
136+
}
137+
}
151138

152-
// Generate Sonatype conform .pom for Bintray Maven-sync, see https://central.sonatype.org/pages/requirements.html
153-
pom.project {
139+
publications {
140+
maven(MavenPublication) {
141+
from components.java
142+
// vavr also publishes a test sources jar
143+
artifact tasks.named('testSourcesJar')
144+
pom {
154145
name = project.name
155146
description = "Vavr is an object-functional library for Java 8+"
156147
url = 'https://www.vavr.io'
157-
inceptionYear '2014'
148+
inceptionYear = '2014'
158149
licenses {
159150
license {
160-
name 'The Apache Software License, Version 2.0'
161-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
151+
name = 'The Apache Software License, Version 2.0'
152+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
162153
}
163154
}
164155
developers {
@@ -179,6 +170,29 @@ uploadArchives {
179170
}
180171
}
181172

173+
// Signing configuration mandatory for Maven Central
174+
signing {
175+
required { !version.endsWith("-SNAPSHOT") }
176+
publishing.publications.configureEach {
177+
sign(it)
178+
}
179+
}
180+
181+
// Configure the publishing repositories for Maven Central
182+
nexusPublishing {
183+
repositories {
184+
sonatype {
185+
username.set(providers.systemProperty("ossrhUsername").forUseAtConfigurationTime())
186+
password.set(providers.systemProperty("ossrhPassword").forUseAtConfigurationTime())
187+
}
188+
}
189+
}
190+
191+
// Configure the "release" plugin
192+
tasks.named('afterReleaseBuild') {
193+
dependsOn "publishToSonatype", "closeAndReleaseSonatypeStagingRepository"
194+
}
195+
182196
release {
183197
buildTasks = ['build']
184198
tagTemplate = '$name-$version'
@@ -188,5 +202,3 @@ release {
188202
pushToCurrentBranch = true
189203
}
190204
}
191-
192-
afterReleaseBuild.dependsOn uploadArchives
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)