|
1 | | -import org.jetbrains.dokka.gradle.DokkaTask |
2 | | -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
3 | | -//import com.jfrog.bintray.gradle.BintrayPlugin |
4 | | -//import com.jfrog.bintray.gradle.BintrayExtension |
5 | | -import java.util.Date |
| 1 | +//import org.jetbrains.dokka.gradle.DokkaTask |
| 2 | +import com.adarshr.gradle.testlogger.theme.ThemeType |
6 | 3 |
|
7 | 4 | plugins { |
8 | | - java |
| 5 | + `java-library` |
9 | 6 | `maven-publish` |
10 | | - kotlin("jvm") version "1.5.31" |
11 | | - id("org.jetbrains.dokka") version "0.10.1" |
| 7 | + signing |
| 8 | + alias(libs.plugins.kotlin.jvm) |
| 9 | +// alias(libs.plugins.dokka) // Generate documentation |
| 10 | + alias(libs.plugins.gitVersion) // Set gitVersion() from last Git repository tag |
| 11 | + alias(libs.plugins.benmanesVersions) // Check for dependency updates |
| 12 | + alias(libs.plugins.testlogger) // Pretty-print test results live to console |
| 13 | + alias(libs.plugins.nexuspublish) // Publish on Maven Central |
| 14 | + alias(libs.plugins.dependencycheck) // Gradle dependency check |
12 | 15 | } |
13 | 16 |
|
14 | | -repositories { |
15 | | - mavenCentral() |
16 | | -} |
17 | 17 |
|
18 | | -val junitVersion = "5.8.1" |
| 18 | +allprojects { |
| 19 | + apply(plugin = "java-library") |
| 20 | + apply(plugin = "maven-publish") |
| 21 | + apply(plugin = "signing") |
| 22 | + apply(plugin = "kotlin") |
| 23 | + apply(plugin = "com.palantir.git-version") |
| 24 | + apply(plugin = "com.github.ben-manes.versions") |
| 25 | + apply(plugin = "com.adarshr.test-logger") |
19 | 26 |
|
20 | | -dependencies { |
21 | | - implementation (kotlin("stdlib-jdk8")) |
22 | | - implementation ("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.4") |
| 27 | + val gitVersion: groovy.lang.Closure<String> by extra |
23 | 28 |
|
24 | | - compileOnly ("com.google.code.findbugs:jsr305:3.0.2") |
| 29 | + group = "dev.pelsmaeker" |
| 30 | + version = gitVersion() |
| 31 | + description = "A disjoint map implementation for the JVM." |
25 | 32 |
|
26 | | - testImplementation ("org.junit.jupiter:junit-jupiter-api:$junitVersion") |
27 | | - testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:$junitVersion") |
28 | | -} |
| 33 | + extra["isSnapshotVersion"] = version.toString().endsWith("-SNAPSHOT") |
| 34 | + extra["isDirtyVersion"] = version.toString().endsWith(".dirty") |
| 35 | + extra["isCI"] = !System.getenv("CI").isNullOrEmpty() |
29 | 36 |
|
30 | | -configure<JavaPluginExtension> { |
31 | | - sourceCompatibility = JavaVersion.VERSION_1_8 |
32 | | - targetCompatibility = JavaVersion.VERSION_1_8 |
33 | | -} |
| 37 | + repositories { |
| 38 | + mavenCentral() |
| 39 | + } |
34 | 40 |
|
35 | | -tasks.withType<KotlinCompile>().configureEach { |
36 | | - kotlinOptions.jvmTarget = "1.8" |
37 | | -} |
| 41 | + tasks.test { |
| 42 | + useJUnitPlatform() |
| 43 | + testlogger { |
| 44 | + theme = ThemeType.MOCHA |
| 45 | + } |
| 46 | + } |
38 | 47 |
|
39 | | -tasks.named<Test>("test") { |
40 | | - useJUnitPlatform() |
41 | | -} |
| 48 | + kotlin { |
| 49 | + jvmToolchain(11) |
| 50 | + } |
| 51 | + |
| 52 | + configure<JavaPluginExtension> { |
| 53 | + withSourcesJar() |
| 54 | +// withJavadocJar() |
| 55 | + } |
| 56 | + |
| 57 | + publishing { |
| 58 | + publications { |
| 59 | + create<MavenPublication>("mavenJava") { |
| 60 | + from(components["java"]) |
42 | 61 |
|
43 | | -tasks.dokka { |
44 | | - outputFormat = "html" |
45 | | - outputDirectory = "$buildDir/javadoc" |
46 | | - configuration { |
47 | | - sourceLink { |
48 | | - path = "src/main/kotlin" |
49 | | - url = "https://github.com/virtlink/disjoint-map/tree/master/src/main/kotlin" |
50 | | - lineSuffix = "#L" |
| 62 | + pom { |
| 63 | + name.set("Disjoint Map") |
| 64 | + description.set(project.description) |
| 65 | + url.set("https://github.com/Virtlink/disjoint-map") |
| 66 | + inceptionYear.set("2023") |
| 67 | + licenses { |
| 68 | + // From: https://spdx.org/licenses/ |
| 69 | + license { |
| 70 | + name.set("Apache-2.0") |
| 71 | + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") |
| 72 | + distribution.set("repo") |
| 73 | + } |
| 74 | + } |
| 75 | + developers { |
| 76 | + developer { |
| 77 | + id.set("virtlink") |
| 78 | + name.set("Daniel A. A. Pelsmaeker") |
| 79 | + |
| 80 | + } |
| 81 | + } |
| 82 | + scm { |
| 83 | + connection.set( "scm:[email protected]:Virtlink/disjoint-map.git") |
| 84 | + developerConnection.set( "scm:[email protected]:Virtlink/disjoint-map.git") |
| 85 | + url.set( "scm:[email protected]:Virtlink/disjoint-map.git") |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + repositories { |
| 91 | + maven { |
| 92 | + name = "GitHubPackages" |
| 93 | + url = uri("https://maven.pkg.github.com/Virtlink/disjoint-map") |
| 94 | + credentials { |
| 95 | + username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") |
| 96 | + password = project.findProperty("gpr.publishKey") as String? ?: System.getenv("GITHUB_TOKEN") |
| 97 | + } |
| 98 | + } |
51 | 99 | } |
52 | 100 | } |
53 | | -} |
54 | 101 |
|
55 | | -val dokkaJar by tasks.creating(Jar::class) { |
56 | | - group = JavaBasePlugin.DOCUMENTATION_GROUP |
57 | | - description = "Assembles Kotlin docs with Dokka" |
58 | | - classifier = "javadoc" |
59 | | - from(tasks.dokka) |
60 | | -} |
| 102 | + signing { |
| 103 | + sign(publishing.publications["mavenJava"]) |
| 104 | + if (!project.hasProperty("signing.secretKeyRingFile")) { |
| 105 | + // If no secretKeyRingFile was set, we assume an in-memory key in the SIGNING_KEY environment variable (used in CI) |
| 106 | + useInMemoryPgpKeys( |
| 107 | + project.findProperty("signing.keyId") as String? ?: System.getenv("SIGNING_KEY_ID"), |
| 108 | + System.getenv("SIGNING_KEY"), |
| 109 | + project.findProperty("signing.password") as String? ?: System.getenv("SIGNING_KEY_PASSWORD"), |
| 110 | + ) |
| 111 | + } |
| 112 | + } |
61 | 113 |
|
62 | | -val sourcesJar by tasks.creating(Jar::class) { |
63 | | - archiveClassifier.set("sources") |
64 | | - from(sourceSets.getByName("main").allSource) |
65 | | -} |
| 114 | + val checkNotDirty by tasks.registering { |
| 115 | + doLast { |
| 116 | + if (project.extra["isDirtyVersion"] as Boolean) { |
| 117 | + throw GradleException("Cannot publish a dirty version: ${project.version}") |
| 118 | + } |
| 119 | + } |
| 120 | + } |
66 | 121 |
|
67 | | -//val githubRepo: String by project |
68 | | -//val githubReadme: String by project |
69 | | -// |
70 | | -//val pomUrl: String by project |
71 | | -//val pomIssueUrl: String by project |
72 | | -//val pomLicenseName: String by project |
73 | | -//val pomLicenseUrl: String by project |
74 | | -//val pomLicenseDist: String by project |
75 | | -//val pomDeveloperId: String by project |
76 | | -//val pomDeveloperName: String by project |
77 | | -//val pomScmUrl: String by project |
78 | | -//val pomScmConnection: String by project |
79 | | -//val pomScmDevConnection: String by project |
80 | | - |
81 | | -//publishing { |
82 | | -// publications { |
83 | | -// create<MavenPublication>("lib") { |
84 | | -// from(components["java"]) |
85 | | -// artifact(dokkaJar) |
86 | | -// artifact(sourcesJar) |
87 | | -// |
88 | | -// pom.withXml { |
89 | | -// asNode().apply { |
90 | | -// appendNode("name", rootProject.name) |
91 | | -// appendNode("description", project.description) |
92 | | -// appendNode("url", pomUrl) |
93 | | -// appendNode("licenses").appendNode("license").apply { |
94 | | -// appendNode("name", pomLicenseName) |
95 | | -// appendNode("url", pomLicenseUrl) |
96 | | -// appendNode("distribution", pomLicenseDist) |
97 | | -// } |
98 | | -// appendNode("developers").appendNode("developer").apply { |
99 | | -// appendNode("id", pomDeveloperId) |
100 | | -// appendNode("name", pomDeveloperName) |
101 | | -// } |
102 | | -// appendNode("scm").apply { |
103 | | -// appendNode("url", pomScmUrl) |
104 | | -// appendNode("connection", pomScmConnection) |
105 | | -// appendNode("developerConnection", pomScmDevConnection) |
106 | | -// } |
107 | | -// } |
108 | | -// } |
109 | | -// } |
110 | | -// } |
111 | | -// |
112 | | -// repositories { |
113 | | -// maven { |
114 | | -// name = "GitHubPackages" |
115 | | -// url = uri("https://maven.pkg.github.com/virtlink/disjoint-map") |
116 | | -// credentials { |
117 | | -// username = System.getenv("GITHUB_ACTOR") |
118 | | -// password = System.getenv("GITHUB_TOKEN") |
| 122 | + tasks.publish { dependsOn(checkNotDirty) } |
| 123 | + |
| 124 | +// tasks.withType<DokkaTask>().configureEach { |
| 125 | + |
| 126 | +// outputFormat = "html" |
| 127 | +// outputDirectory = "$buildDir/javadoc" |
| 128 | +// configuration { |
| 129 | +// sourceLink { |
| 130 | +// path = "src/main/kotlin" |
| 131 | +// url = "https://github.com/virtlink/disjoint-map/tree/master/src/main/kotlin" |
| 132 | +// lineSuffix = "#L" |
119 | 133 | // } |
120 | 134 | // } |
121 | 135 | // } |
122 | | -//} |
123 | 136 |
|
124 | | -//bintray { |
125 | | -// user = project.findProperty("bintrayUser").toString() |
126 | | -// key = project.findProperty("bintrayKey").toString() |
127 | | -// setPublications("lib") |
128 | | -// publish = true |
129 | | -// |
130 | | -// pkg.apply { |
131 | | -// name = project.name |
132 | | -// desc = project.description |
133 | | -// websiteUrl = pomUrl |
134 | | -// issueTrackerUrl = pomIssueUrl |
135 | | -// vcsUrl = pomUrl + ".git" |
136 | | -// githubRepo = githubRepo |
137 | | -// setLicenses("Apache-2.0") |
138 | | -// repo = project.findProperty("bintrayRepo").toString() |
139 | | -// publicDownloadNumbers = true |
140 | | -// setLabels("kotlin", "disjoint", "map", "set", "collection") |
141 | | -// |
142 | | -// githubReleaseNotesFile = githubReadme |
| 137 | +// val dokkaJar by tasks.creating(Jar::class) { |
| 138 | +// group = JavaBasePlugin.DOCUMENTATION_GROUP |
| 139 | +// description = "Assembles Kotlin docs with Dokka" |
| 140 | +// classifier = "javadoc" |
| 141 | +// from(tasks.dokka) |
| 142 | +// } |
143 | 143 | // |
144 | | -// version.apply { |
145 | | -// name = project.version.toString() |
146 | | -// desc = project.description |
147 | | -// released = Date().toString() |
148 | | -// vcsTag = project.version.toString() |
149 | | -// gpg.apply { |
150 | | -// sign = true |
151 | | -// passphrase = project.findProperty("gpgPassphrase").toString() |
152 | | -// } |
153 | | -// mavenCentralSync.apply { |
154 | | -// sync = true |
155 | | -// user = project.findProperty("sonatypeUsername").toString() |
156 | | -// password = project.findProperty("sonatypePassword").toString() |
157 | | -// } |
158 | | -// } |
| 144 | +// val sourcesJar by tasks.creating(Jar::class) { |
| 145 | +// archiveClassifier.set("sources") |
| 146 | +// from(sourceSets.getByName("main").allSource) |
159 | 147 | // } |
160 | | -//} |
| 148 | +} |
| 149 | + |
| 150 | + |
| 151 | +nexusPublishing { |
| 152 | + repositories { |
| 153 | + sonatype { |
| 154 | + nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) |
| 155 | + snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) |
| 156 | + username.set(project.findProperty("ossrh.user") as String? ?: System.getenv("OSSRH_USERNAME")) |
| 157 | + password.set(project.findProperty("ossrh.token") as String? ?: System.getenv("OSSRH_TOKEN")) |
| 158 | + } |
| 159 | + } |
| 160 | +} |
0 commit comments