forked from eclipse-edc/GradlePlugins
/
build.gradle.kts
172 lines (153 loc) · 5.72 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
checkstyle
`maven-publish`
signing
`java-library`
`version-catalog`
// for publishing to nexus/ossrh/mavencentral
id("org.gradle.crypto.checksum") version "1.4.0"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("com.gradle.plugin-publish") version "1.1.0" apply false
}
val groupId: String by project
val defaultVersion: String by project
val jupiterVersion: String by project
val assertj: String by project
val mockitoVersion: String by project
var actualVersion: String = (project.findProperty("version") ?: defaultVersion) as String
if (actualVersion == "unspecified") {
actualVersion = defaultVersion
}
allprojects {
apply(plugin = "checkstyle")
apply(plugin = "maven-publish")
version = actualVersion
group = groupId
// for all gradle plugins:
pluginManager.withPlugin("java-gradle-plugin") {
apply(plugin = "com.gradle.plugin-publish")
}
if (!project.hasProperty("skip.signing")) {
apply(plugin = "signing")
//set the deploy-url only for java libraries
val deployUrl =
if (actualVersion.contains("SNAPSHOT")) "https://oss.sonatype.org/content/repositories/snapshots/"
else "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
publishing {
repositories {
maven {
name = "OSSRH"
setUrl(deployUrl)
credentials {
username = System.getenv("OSSRH_USER") ?: return@credentials
password = System.getenv("OSSRH_PASSWORD") ?: return@credentials
}
}
}
signing {
useGpgCmd()
sign(publishing.publications)
}
}
}
// for all java libs:
pluginManager.withPlugin("java-library") {
java {
val javaVersion = 11
toolchain {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
}
tasks.withType(JavaCompile::class.java) {
// making sure the code does not use any APIs from a more recent version.
// Ref: https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
options.release.set(javaVersion)
}
withJavadocJar()
withSourcesJar()
}
dependencies {
// Use JUnit test framework for unit tests
testImplementation("org.junit.jupiter:junit-jupiter-api:${jupiterVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${jupiterVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${jupiterVersion}")
testImplementation("org.assertj:assertj-core:${assertj}")
testImplementation("org.mockito:mockito-core:${mockitoVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}")
}
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}
// configure checkstyle version
checkstyle {
toolVersion = "10.0"
maxErrors = 0 // does not tolerate errors
}
repositories {
mavenCentral()
}
// let's not generate any reports because that is done from within the Github Actions workflow
tasks.withType<Checkstyle> {
reports {
html.required.set(false)
xml.required.set(true)
}
}
afterEvaluate {
// values needed for publishing
val pluginsWebsiteUrl: String by project
val pluginsDeveloperId: String by project
val pluginsDeveloperName: String by project
val pluginsDeveloperEmail: String by project
val pluginsScmConnection: String by project
val pluginsScmUrl: String by project
publishing {
publications.forEach { i ->
val mp = (i as MavenPublication)
mp.pom {
name.set(project.name)
description.set("edc :: ${project.name}")
url.set(pluginsWebsiteUrl)
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
developers {
developer {
id.set(pluginsDeveloperId)
name.set(pluginsDeveloperName)
email.set(pluginsDeveloperEmail)
}
}
scm {
connection.set(pluginsScmConnection)
url.set(pluginsScmUrl)
}
}
}
// println("\nset POM for: ${mp.groupId}:${mp.artifactId}:${mp.version}")
}
}
}
tasks.withType<Jar> {
metaInf {
from("${rootProject.projectDir.path}/NOTICE.md")
from("${rootProject.projectDir.path}/LICENSE")
}
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
username.set(System.getenv("OSSRH_USER") ?: return@sonatype)
password.set(System.getenv("OSSRH_PASSWORD") ?: return@sonatype)
}
}
}