Skip to content

Commit 4edf9c8

Browse files
authored
Build and release improvements / enhancements (#615)
* Upgrade to gradle 8.1.1 * Manage dependencies in libs.versions.toml * Allow gradle to manage jdk toolchain * Address javadoc build errors * Enable artifact publication. * Enable non-jdk8 testing on github PRs
1 parent d28472d commit 4edf9c8

22 files changed

+324
-97
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
- name: Compile and assemble main project with Temurin JDK ${{ matrix.test-jdk-version }}
3535
run: ./gradlew clean assemble
3636
- name: Test with Temurin JDK ${{ matrix.test-jdk-version }}
37-
run: ./gradlew -S test
37+
run: ./gradlew -S test${{ matrix.test-jdk-version }}

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ Update the version of the SDK before creating a new release. The format is `<maj
9898
`<major>.<minor>` numbers must match the version of BP. The `<patch>` is an incrementing number that increments with
9999
each SDK release for a given major/minor release.
100100

101-
The version is specified in the `buildSrc/src/main/kotlin/ds3-java-sdk-version.gradle.kts` file:
101+
The version is specified in `libs.versions.toml`:
102102

103103
```
104-
group = "com.spectralogic.ds3"
105-
version = "5.4.1"
104+
[versions]
105+
#
106+
# project version
107+
#
108+
ds3SdkVersion = "5.6.0"
106109
```
107110

108111
When a release is created in github, it is automatically published on [jitpack.io](https://jitpack.io/#SpectraLogic/ds3_java_sdk).

build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2002 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
tasks.wrapper {
17+
// to upgrade the gradle wrapper, bump the version below and run ./gradlew wrapper twice
18+
gradleVersion = "8.1.1"
19+
}

buildSrc/build.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ plugins {
1717
`kotlin-dsl`
1818
}
1919

20-
repositories {
21-
mavenCentral()
22-
}
23-
2420
dependencies {
25-
implementation("org.owasp:dependency-check-gradle:7.3.2")
21+
implementation(libs.kotlinJvmPlugin)
22+
implementation(libs.owaspDepCheckPlugin)
23+
implementation(libs.versionsPlugin)
2624
}

buildSrc/settings.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* ****************************************************************************
3+
* Copyright 2023 Spectra Logic Corporation. All Rights Reserved.
4+
* ***************************************************************************
5+
*/
6+
7+
rootProject.name = "buildSrc"
8+
9+
dependencyResolutionManagement {
10+
repositories {
11+
mavenCentral()
12+
gradlePluginPortal()
13+
versionCatalogs {
14+
create("libs") {
15+
from(files("../libs.versions.toml"))
16+
}
17+
}
18+
}
19+
}

buildSrc/src/main/kotlin/ds3-java-sdk-internal-convention.gradle.kts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
plugins {
1717
`java`
1818
`jacoco`
19+
id("com.github.ben-manes.versions")
1920
}
2021

21-
tasks.compileJava {
22-
options.encoding = "UTF-8"
23-
// since java 8 is the minimum version supported, make sure we always
24-
// produce java 8 bytecode
25-
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
26-
options.release.set(8)
27-
} else {
28-
// java 8 does not have a release option, so use source and target compatibility
29-
setSourceCompatibility(JavaVersion.VERSION_1_8.toString())
30-
setTargetCompatibility(JavaVersion.VERSION_1_8.toString())
22+
java {
23+
toolchain {
24+
languageVersion.set(JavaLanguageVersion.of(8))
3125
}
3226
}
3327

@@ -45,3 +39,20 @@ tasks.jacocoTestReport {
4539
tasks.test {
4640
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
4741
}
42+
43+
// convenience task name for github tests
44+
tasks.register<Test>("test8") {
45+
dependsOn(tasks.test)
46+
}
47+
48+
tasks.register<Test>("test11") {
49+
javaLauncher.set(javaToolchains.launcherFor {
50+
languageVersion.set(JavaLanguageVersion.of(11))
51+
})
52+
}
53+
54+
tasks.register<Test>("test17") {
55+
javaLauncher.set(javaToolchains.launcherFor {
56+
languageVersion.set(JavaLanguageVersion.of(17))
57+
})
58+
}

buildSrc/src/main/kotlin/ds3-java-sdk-library-convention.gradle.kts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,46 @@
1414
*/
1515

1616
plugins {
17-
id("ds3-java-sdk-internal-convention")
1817
id("ds3-java-sdk-version")
18+
id("ds3-java-sdk-internal-convention")
19+
id("org.jetbrains.kotlin.jvm")
1920
`java-library`
2021
`maven-publish`
22+
id("ds3-java-sdk-publishing-common-convention")
23+
signing
2124
id("org.owasp.dependencycheck")
2225
}
2326

27+
kotlin {
28+
jvmToolchain {
29+
(this as JavaToolchainSpec).apply {
30+
languageVersion.set(JavaLanguageVersion.of("8"))
31+
vendor.set(JvmVendorSpec.ADOPTIUM)
32+
}
33+
}
34+
}
35+
36+
java {
37+
withJavadocJar()
38+
withSourcesJar()
39+
}
40+
2441
publishing {
2542
publications {
26-
create<MavenPublication>("ProjectPublication") {
43+
create<MavenPublication>("Project") {
2744
from(components["java"])
2845
}
2946
}
3047
}
3148

49+
signing {
50+
setRequired({
51+
(extra["isReleaseVersion"] as Boolean) && gradle.taskGraph.hasTask("publishProjectPublicationToOSSRHRepository")
52+
})
53+
useGpgCmd()
54+
sign(publishing.publications["Project"])
55+
}
56+
3257
dependencyCheck {
3358
// fail the build if any vulnerable dependencies are identified (CVSS score > 0)
3459
failBuildOnCVSS = 0f;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import org.gradle.api.publish.maven.MavenPublication
2+
3+
/*
4+
* ******************************************************************************
5+
* Copyright 2002 Spectra Logic Corporation. All Rights Reserved.
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
7+
* this file except in compliance with the License. A copy of the License is located at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* or in the "license" file accompanying this file.
12+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
* specific language governing permissions and limitations under the License.
15+
* ****************************************************************************
16+
*/
17+
18+
plugins {
19+
`maven-publish`
20+
signing
21+
}
22+
23+
publishing {
24+
repositories {
25+
maven {
26+
name = "internal"
27+
val releasesRepoUrl = "https://artifacts.eng.sldomain.com/repository/spectra-releases/"
28+
val snapshotsRepoUrl = "https://artifacts.eng.sldomain.com/repository/spectra-snapshots/"
29+
url = uri(if (extra["isReleaseVersion"] as Boolean) releasesRepoUrl else snapshotsRepoUrl)
30+
credentials {
31+
username = extra.has("artifactsUsername").let {
32+
if (it) extra.get("artifactsUsername") as String else null
33+
}
34+
password = extra.has("artifactsPassword").let {
35+
if (it) extra.get("artifactsPassword") as String else null
36+
}
37+
}
38+
}
39+
maven {
40+
name = "OSSRH"
41+
val releasesOssrhRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
42+
val snapshotsOssrhRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
43+
url = uri(if (extra["isReleaseVersion"] as Boolean) releasesOssrhRepoUrl else snapshotsOssrhRepoUrl)
44+
credentials {
45+
username = extra.has("ossrhUsername").let {
46+
if (it) extra.get("ossrhUsername") as String else null
47+
}
48+
password = extra.has("ossrhPassword").let {
49+
if (it) extra.get("ossrhPassword") as String else null
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
tasks.register("publishToInternalRepository") {
57+
group = "publishing"
58+
description = "Publishes all Maven publications to the internal Maven repository."
59+
dependsOn(tasks.withType<PublishToMavenRepository>().matching {
60+
it.repository == publishing.repositories["internal"]
61+
})
62+
}
63+
64+
tasks.register("publishToSonatypeOSSRH") {
65+
group = "publishing"
66+
description = "Publishes all Maven publications to Sonatype's OSSRH repository."
67+
dependsOn(tasks.withType<PublishToMavenRepository>().matching {
68+
it.repository == publishing.repositories["OSSRH"]
69+
})
70+
}
71+
72+
val augmentPom = tasks.register("augmentPom") {
73+
publishing.publications.filterIsInstance<MavenPublication>().forEach { pub ->
74+
pub.pom {
75+
name.set("${project.group}:${project.name}")
76+
url.set("https://github.com/SpectraLogic/ds3_java_sdk")
77+
licenses {
78+
license {
79+
name.set("The Apache License, Version 2.0")
80+
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
81+
}
82+
}
83+
developers {
84+
developer {
85+
name.set("Spectra Logic Developers")
86+
email.set("[email protected]")
87+
organization.set("Spectra Logic")
88+
organizationUrl.set("https://spectralogic.com/")
89+
}
90+
}
91+
scm {
92+
connection.set("scm:git:https://github.com/SpectraLogic/ds3_java_sdk.git")
93+
developerConnection.set("scm:git:https://github.com/SpectraLogic/ds3_java_sdk.git")
94+
url.set("https://github.com/SpectraLogic/ds3_java_sdk")
95+
}
96+
}
97+
}
98+
}
99+
100+
tasks.withType<GenerateMavenPom>().configureEach {
101+
dependsOn(augmentPom)
102+
}
103+
104+
tasks.withType<Sign>().configureEach {
105+
onlyIf("isReleaseVersion is set") { project.extra["isReleaseVersion"] as Boolean }
106+
}

buildSrc/src/main/kotlin/ds3-java-sdk-version.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
* ****************************************************************************
1414
*/
1515

16+
val catalogs = extensions
17+
.getByType<VersionCatalogsExtension>()
18+
1619
group = "com.spectralogic.ds3"
17-
version = "5.6.0"
20+
version = catalogs.named("libs").findVersion("ds3SdkVersion").get().requiredVersion
21+
22+
extra["isReleaseVersion"] = !version.toString().endsWith("SNAPSHOT")

ds3-bom/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
plugins {
1717
`ds3-java-sdk-version`
1818
`maven-publish`
19+
`ds3-java-sdk-publishing-common-convention`
20+
signing
1921
`java-platform`
2022
}
2123

@@ -37,3 +39,11 @@ publishing {
3739
}
3840
}
3941
}
42+
43+
signing {
44+
setRequired({
45+
(extra["isReleaseVersion"] as Boolean) && gradle.taskGraph.hasTask("publishProjectPublicationToOSSRHRepository")
46+
})
47+
useGpgCmd()
48+
sign(publishing.publications["Ds3Bom"])
49+
}

0 commit comments

Comments
 (0)