Skip to content

Commit 4d77eb3

Browse files
committed
update build
1 parent f7a6863 commit 4d77eb3

9 files changed

Lines changed: 248 additions & 193 deletions

build.gradle.kts

Lines changed: 77 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,215 +1,102 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
4+
`java-library`
25
groovy
3-
id("maven-publish")
4-
id("signing")
5-
id("org.jetbrains.kotlin.jvm") version("1.4.30")
6-
id("com.github.ben-manes.versions") version ("0.36.0")
6+
kotlin
7+
jacoco
8+
alias(libs.plugins.updates)
9+
id("openapiprocessor.test")
10+
id("openapiprocessor.testInt")
11+
id("openapiprocessor.publish")
12+
id("jacoco-report-aggregation")
713
}
814

915
val projectGroupId: String by project
1016
val projectVersion: String by project
1117

12-
group = projectGroupId
13-
version = projectVersion
14-
15-
tasks.compileKotlin {
16-
kotlinOptions.jvmTarget = "1.8"
17-
}
18-
19-
fun getBuildProperty(property: String): String {
20-
val prop: String? = project.findProperty(property) as String?
21-
if(prop != null) {
22-
return prop
23-
}
24-
25-
val env: String? = System.getenv(property)
26-
if (env != null) {
27-
return env
28-
}
18+
group = "io.openapiprocessor"
19+
version = libs.versions.processor.get()
20+
println("version: $version")
2921

30-
return "n/a"
22+
java {
23+
withJavadocJar ()
24+
withSourcesJar ()
3125
}
3226

33-
fun getBuildSignKey(property: String): String {
34-
val prop: String? = project.findProperty(property) as String?
35-
if(prop != null) {
36-
return prop
37-
}
27+
kotlin {
28+
jvmToolchain(libs.versions.build.jdk.get().toInt())
3829

39-
val env: String? = System.getenv(property)
40-
if (env != null) {
41-
return env.replace("\\n", "\n")
30+
compilerOptions {
31+
freeCompilerArgs.add("-Xannotation-default-target=param-property")
32+
jvmTarget = JvmTarget.fromTarget(libs.versions.target.jdk.get())
4233
}
43-
44-
return "n/a"
45-
}
46-
47-
fun isReleaseVersion(): Boolean {
48-
return !(project.version.toString().endsWith("SNAPSHOT"))
49-
}
50-
51-
project.ext {
52-
set("processorApiVersion", "2021.1")
53-
54-
set("publishUser", getBuildProperty("PUBLISH_USER"))
55-
set("publishKey", getBuildProperty("PUBLISH_KEY"))
56-
set("signKey", getBuildSignKey("SIGN_KEY"))
57-
set("signPwd", getBuildProperty("SIGN_PWD"))
5834
}
5935

60-
61-
repositories {
62-
mavenCentral()
63-
maven {
64-
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
65-
mavenContent {
66-
snapshotsOnly()
67-
}
68-
}
69-
jcenter()
36+
tasks.compileTestGroovy {
37+
classpath += sourceSets.main.get().compileClasspath
38+
classpath += files(tasks.compileKotlin.get().destinationDirectory)
39+
classpath += files(tasks.compileTestKotlin.get().destinationDirectory)
7040
}
7141

7242
dependencies {
73-
implementation(kotlin("stdlib-jdk8"))
43+
implementation (libs.openapi.processor.api)
7444

7545
implementation("io.swagger.parser.v3:swagger-parser:2.0.24") {
7646
exclude(group = "io.swagger.parser.v3", module = "swagger-parser-v2-converter")
7747
exclude(group = "io.swagger.core.v3", module = "swagger-annotations")
7848
}
79-
compileOnly("io.openapiprocessor:openapi-processor-api:${project.ext.get("processorApiVersion")}")
80-
81-
testImplementation("net.bytebuddy:byte-buddy:1.10.20")
82-
testImplementation("org.spockframework:spock-core:1.3-groovy-2.5") {
83-
exclude(group = "org.codehaus.groovy", module = "groovy-json")
84-
exclude(group = "org.codehaus.groovy", module = "groovy-macro")
85-
exclude(group = "org.codehaus.groovy", module = "groovy-sql")
86-
exclude(group = "org.codehaus.groovy", module = "groovy-templates")
87-
exclude(group = "org.codehaus.groovy", module = "groovy-xml")
88-
}
89-
testImplementation("io.github.java-diff-utils:java-diff-utils:4.9")
90-
testImplementation("io.openapiprocessor:openapi-processor-api:${project.ext.get("processorApiVersion")}")
91-
}
92-
93-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
94-
kotlinOptions.jvmTarget = "1.8"
95-
}
96-
97-
tasks.withType<GroovyCompile> {
98-
dependsOn("compileKotlin")
99-
classpath += files(tasks.compileKotlin.get().destinationDir)
100-
}
101-
102-
val sourcesJar by tasks.registering(Jar::class) {
103-
archiveClassifier.set("sources")
104-
from(sourceSets.main.get().allSource)
105-
}
106-
107-
val javadocJar by tasks.registering(Jar::class) {
108-
dependsOn("javadoc")
109-
archiveClassifier.set("javadoc")
110-
from(tasks.javadoc.get().destinationDir)
111-
}
112-
113-
artifacts {
114-
archives(sourcesJar)
115-
archives(javadocJar)
116-
}
117-
118-
119-
val projectTitle: String by project
120-
val projectDesc: String by project
121-
val projectUrl: String by project
122-
val projectGithubRepo: String by project
123-
124-
// does not work on oss.sonatype.org
125-
tasks.withType<GenerateModuleMetadata>().configureEach {
126-
enabled = false
127-
}
128-
129-
publishing {
130-
publications {
131-
create<MavenPublication>("OpenApiProcessor") {
132-
from(components["java"])
133-
artifact(sourcesJar.get())
134-
artifact(javadocJar.get())
135-
136-
groupId = project.group.toString()
137-
artifactId = project.name
138-
version = project.version.toString()
139-
140-
pom {
141-
name.set(projectTitle)
142-
description.set(projectDesc)
143-
url.set(projectUrl)
144-
145-
licenses {
146-
license {
147-
name.set("The Apache License, Version 2.0")
148-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
149-
distribution.set("repo")
150-
}
151-
}
152-
153-
developers {
154-
developer {
155-
id.set("hauner")
156-
name.set("Martin Hauner")
157-
}
158-
}
159-
160-
scm {
161-
url.set("https://github.com/${projectGithubRepo}")
162-
}
163-
}
164-
}
165-
}
166-
167-
repositories {
168-
maven {
169-
val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
170-
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
171-
url = uri(if (isReleaseVersion()) releasesRepoUrl else snapshotsRepoUrl)
172-
173-
credentials {
174-
username = project.extra["publishUser"].toString()
175-
password = project.extra["publishKey"].toString()
176-
}
177-
}
178-
}
179-
}
180-
181-
//tasks.withType<Sign>().configureEach {
182-
// onlyIf { isReleaseVersion() }
183-
//}
184-
185-
signing {
186-
useInMemoryPgpKeys(
187-
project.extra["signKey"].toString(),
188-
project.extra["signPwd"].toString())
189-
190-
sign(publishing.publications["OpenApiProcessor"])
191-
}
19249

193-
194-
registerPublishTask("snapshot") { hasSnapshotVersion() }
195-
registerPublishTask("release") { !hasSnapshotVersion() }
196-
197-
fun registerPublishTask(type: String, condition: () -> Boolean) {
198-
tasks.register("publish${type.capitalize()}") {
199-
group = "publishing"
200-
description = "Publish only if the current version is a ${type.capitalize()} version"
201-
202-
if (condition()) {
203-
println("enabling $type publishing")
204-
dependsOn(tasks.withType<PublishToMavenRepository>())
205-
} else {
206-
doLast {
207-
println("skipping - no $type version")
208-
}
209-
}
50+
testImplementation("io.github.java-diff-utils:java-diff-utils:4.9")
51+
testImplementation (platform(libs.groovy.bom))
52+
testImplementation ("org.apache.groovy:groovy")
53+
testImplementation ("org.apache.groovy:groovy-nio")
54+
testImplementation (libs.spock)
55+
testImplementation (platform(libs.kotest.bom))
56+
testImplementation (libs.kotest.runner)
57+
testImplementation (libs.kotest.table)
58+
testImplementation (libs.mockk)
59+
testImplementation (libs.logback)
60+
61+
testIntImplementation("io.github.java-diff-utils:java-diff-utils:4.9")
62+
testIntImplementation (platform(libs.groovy.bom))
63+
testIntImplementation ("org.apache.groovy:groovy")
64+
testIntImplementation ("org.apache.groovy:groovy-nio")
65+
testIntImplementation (libs.spock)
66+
testIntImplementation (platform(libs.kotest.bom))
67+
testIntImplementation (libs.kotest.runner)
68+
testIntImplementation (libs.kotest.table)
69+
testIntImplementation (libs.mockk)
70+
testIntImplementation (libs.logback)
71+
}
72+
73+
tasks.withType<Test>().configureEach {
74+
// jvmArgs(listOf(
75+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
76+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
77+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
78+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
79+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
80+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
81+
// ))
82+
83+
finalizedBy(tasks.named("jacocoTestReport"))
84+
}
85+
86+
jacoco {
87+
toolVersion = libs.versions.jacoco.get()
88+
}
89+
90+
tasks.jacocoTestReport {
91+
executionData.from(tasks.named<Test>("test").map<File> {
92+
it.extensions.getByType(JacocoTaskExtension::class.java).destinationFile as File
93+
})
94+
executionData.from(tasks.named<Test>("testInt").map<File> {
95+
it.extensions.getByType(JacocoTaskExtension::class.java).destinationFile as File
96+
})
97+
98+
reports {
99+
xml.required = true
100+
html.required = true
210101
}
211102
}
212-
213-
fun hasSnapshotVersion(): Boolean {
214-
return version.toString().endsWith("-SNAPSHOT")
215-
}

buildSrc/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
dependencies {
6+
// catalog hack: https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
7+
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
8+
9+
implementation(libs.plugin.kotlin)
10+
implementation(libs.plugin.build)
11+
}

buildSrc/settings.gradle.kts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")
2+
3+
pluginManagement {
4+
repositories {
5+
gradlePluginPortal()
6+
mavenCentral()
7+
}
8+
}
9+
10+
dependencyResolutionManagement {
11+
versionCatalogs {
12+
create("libs") {
13+
from(files("../gradle/libs.versions.toml"))
14+
}
15+
}
16+
17+
repositories {
18+
gradlePluginPortal()
19+
mavenCentral()
20+
maven {
21+
url = uri("https://central.sonatype.com/repository/maven-snapshots")
22+
mavenContent {
23+
snapshotsOnly()
24+
}
25+
}
26+
}
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
`maven-publish`
3+
signing
4+
id("io.openapiprocessor.build.plugin.publish")
5+
}
6+
7+
publishing {
8+
publications {
9+
create<MavenPublication>("openapiprocessor") {
10+
from(components["java"])
11+
}
12+
}
13+
}
14+
15+
publishingCentral {
16+
deploymentName = "json"
17+
waitFor = "VALIDATED"
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")
2+
3+
import org.gradle.accessors.dm.LibrariesForLibs
4+
5+
plugins {
6+
java
7+
groovy
8+
kotlin
9+
}
10+
11+
// see buildSrc/build.gradle.kts
12+
val libs = the<LibrariesForLibs>()
13+
14+
testing {
15+
suites {
16+
val test by getting(JvmTestSuite::class) {
17+
useJUnitJupiter(libs.versions.junit.get())
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)