5
5
* -> test reports: ./build/reports/tests/test/index.html
6
6
* -> coverage reports: ./build/reports/jacoco/test/html/index.html
7
7
* -> javadoc: `./build/docs/javadoc`
8
- *
8
+ *
9
9
* - 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
10
29
*/
11
30
plugins {
12
- id " net.researchgate.release" version " 2.8.1"
13
- }
14
31
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
+ }
20
42
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 '
23
45
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' )
25
50
26
51
repositories {
27
- mavenLocal()
28
52
mavenCentral()
29
53
}
30
54
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))
41
67
}
68
+ withSourcesJar()
69
+ withJavadocJar()
42
70
}
43
71
72
+ sourceSets. main. java. srcDirs + = [' src-gen/main/java' ]
73
+ sourceSets. test. java. srcDirs + = [' src-gen/test/java' ]
74
+
44
75
task generateSources () {
45
76
doLast {
46
77
delete ' src-gen'
@@ -62,103 +93,63 @@ task generateSources() {
62
93
63
94
compileJava. dependsOn ' generateSources'
64
95
65
- tasks. withType(JavaCompile ) {
66
- sourceCompatibility = 8
67
- targetCompatibility = 8
96
+ tasks. withType(JavaCompile ). configureEach {
68
97
options. encoding = ' UTF-8'
69
98
options. compilerArgs = [ ' -Werror' , ' -Xlint:all' , ' -Xlint:-deprecation' ]
70
99
}
71
100
72
- dependencies {
73
- testImplementation " junit:junit:$junitVersion "
74
- testImplementation " org.assertj:assertj-core:$assertjVersion "
75
- }
76
-
77
- jacocoTestReport {
101
+ tasks. named(' jacocoTestReport' ) {
78
102
reports {
79
103
xml. enabled = true
80
104
}
81
105
}
82
106
83
- check {
107
+ tasks . named( ' check' ) {
84
108
dependsOn jacocoTestReport
85
109
dependsOn javadoc
86
110
}
87
111
88
- jar {
112
+ tasks . named( ' jar' ) {
89
113
manifest {
90
114
attributes(' Automatic-Module-Name' : ' io.vavr' )
91
115
}
92
116
}
93
117
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 ) {
100
119
from sourceSets. test. allSource
101
120
archiveClassifier = ' test-sources'
102
121
}
103
122
104
- task javadocJar (type : Jar ) {
105
- from javadoc
106
- archiveClassifier = ' javadoc'
107
- }
123
+ // -- --
124
+ // -- PUBLISHING & RELEASING --
125
+ // -- --
108
126
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 {
136
129
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
+ }
151
138
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 {
154
145
name = project. name
155
146
description = " Vavr is an object-functional library for Java 8+"
156
147
url = ' https://www.vavr.io'
157
- inceptionYear ' 2014'
148
+ inceptionYear = ' 2014'
158
149
licenses {
159
150
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'
162
153
}
163
154
}
164
155
developers {
@@ -179,6 +170,29 @@ uploadArchives {
179
170
}
180
171
}
181
172
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
+
182
196
release {
183
197
buildTasks = [' build' ]
184
198
tagTemplate = ' $name-$version'
@@ -188,5 +202,3 @@ release {
188
202
pushToCurrentBranch = true
189
203
}
190
204
}
191
-
192
- afterReleaseBuild. dependsOn uploadArchives
0 commit comments