-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move common logic to buildSrc/ and split build to files per project
Note: smaller commits are not possible because I couldn't find out how to apply a bulidSrc/*/*.gradle.kts script to subprojects {} ...
- Loading branch information
Showing
9 changed files
with
486 additions
and
457 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
plugins { | ||
kotlin("jvm") version "1.3.50" | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
url = uri("https://plugins.gradle.org/m2/") | ||
} | ||
} | ||
|
||
dependencies { | ||
// external plugins | ||
implementation("com.github.spotbugs:spotbugs-gradle-plugin:3.0.0") | ||
implementation("biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.1") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
buildSrc/src/main/kotlin/dataprovider-library.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
import com.github.spotbugs.SpotBugsExtension | ||
import org.w3c.dom.Element | ||
import org.w3c.dom.NodeList | ||
|
||
plugins { | ||
`java-library` | ||
jacoco | ||
|
||
id("com.github.spotbugs") | ||
id("biz.aQute.bnd.builder") | ||
|
||
`maven-publish` | ||
signing | ||
} | ||
|
||
val isBuildOnJenkins: Boolean by rootProject.extra | ||
val skipSpotBugs: Boolean by rootProject.extra | ||
val deps: Dependencies by rootProject.extra | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
group = rootProject.group | ||
version = rootProject.version | ||
|
||
dependencies { | ||
"compileOnly"(deps.spotBugsAnnotations) | ||
"testImplementation"(deps.spotBugsAnnotations) | ||
} | ||
|
||
configure<JavaPluginExtension> { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
// configure after properties are set and integration tests are added | ||
configure<JacocoPluginExtension> { | ||
toolVersion = "0.8.3" | ||
} | ||
|
||
configure<SpotBugsExtension> { | ||
toolVersion = "3.1.12" | ||
isIgnoreFailures = true | ||
} | ||
|
||
tasks { | ||
withType<JavaCompile> { | ||
options.encoding = "UTF-8" | ||
options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror")) | ||
} | ||
|
||
withType<Jar> { | ||
from(rootProject.rootDir) { | ||
include("LICENSE", "NOTICE") | ||
into("META-INF") | ||
} | ||
} | ||
|
||
named<Javadoc>("javadoc") { | ||
if (JavaVersion.current().isJava9Compatible) { | ||
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true) | ||
} | ||
} | ||
|
||
named<Jar>("jar") { | ||
manifest { | ||
val now = LocalDate.now() | ||
|
||
val title = project.the<BasePluginConvention>().archivesBaseName | ||
val company = "TNG Technology Consulting GmbH" | ||
val today = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) | ||
val copyright = "${now.year} $company" | ||
|
||
attributes( | ||
"Built-By" to "Gradle ${gradle.gradleVersion}", | ||
"Built-Date" to today, // using now would destroy incremental build feature | ||
"Specification-Title" to title, | ||
"Specification-Version" to archiveVersion, | ||
"Specification-Vendor" to company, | ||
"Implementation-Title" to title, | ||
"Implementation-Version" to archiveVersion, | ||
"Implementation-Vendor" to company, | ||
"Issue-Tracker" to "https://github.com/TNG/junit-dataprovider/issues", | ||
"Documentation-URL" to "https://github.com/TNG/junit-dataprovider/wiki", | ||
"Copyright" to copyright, | ||
"License" to "Apache License v2.0, January 2004", | ||
|
||
// OSGi / p2 plugin information | ||
"Bundle-Copyright" to copyright, | ||
"Bundle-Name" to title, | ||
"Bundle-SymbolicName" to "${project.group}.$title", | ||
"Bundle-Vendor" to company, | ||
"Export-Package" to "com.tngtech.junit.dataprovider.*", | ||
|
||
// Bnd plugin instructions -- remove field because it breaks caching builds with included linux timestamp | ||
"-removeheaders" to "Bnd-LastModified" | ||
) | ||
} | ||
} | ||
|
||
withType<com.github.spotbugs.SpotBugsTask> { | ||
enabled = !skipSpotBugs | ||
} | ||
|
||
val test = named<Test>("test") { | ||
ignoreFailures = isBuildOnJenkins | ||
} | ||
|
||
val touchTestResultsForJenkins = register<TouchTestResults>("touchTestResultsForJenkins") { | ||
tasks(test) | ||
enabled = isBuildOnJenkins | ||
} | ||
named("build") { | ||
dependsOn(touchTestResultsForJenkins) | ||
} | ||
} | ||
|
||
// -- sign and publish artifacts ------------------------------------------------------------------------------------- | ||
val isReleaseVersion by extra(!project.version.toString().endsWith("-SNAPSHOT")) | ||
|
||
// username and password from gradle.properties otherwise empty | ||
val sonatypeUsername by extra(findProperty("sonatypeUsername")?.toString() ?: "") | ||
val sonatypePassword by extra(findProperty("sonatypePassword")?.toString() ?: "") | ||
|
||
tasks.withType<GenerateModuleMetadata> { | ||
enabled = isReleaseVersion // signing of these artifacts causes failure for snapshot versions | ||
} | ||
|
||
configure<PublishingExtension> { | ||
publications { | ||
register<MavenPublication>("mavenJava") { | ||
val archivesBaseName = project.the<BasePluginConvention>().archivesBaseName | ||
artifactId = archivesBaseName | ||
from(components["java"]) | ||
pom { | ||
packaging = "jar" | ||
|
||
name.set(archivesBaseName) | ||
description.set(project.description) | ||
url.set("https://github.com/TNG/junit-dataprovider") | ||
|
||
developers { | ||
developer { | ||
id.set("aaschmid") | ||
name.set("Andreas Schmid") | ||
email.set("service@aaschmid.de") | ||
} | ||
} | ||
|
||
licenses { | ||
license { | ||
name.set("The Apache Software License, Version 2.0") | ||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
distribution.set("repo") | ||
} | ||
} | ||
|
||
scm { | ||
connection.set("scm:git@github.com:TNG/junit-dataprovider.git") | ||
developerConnection.set("scm:git@github.com:TNG/junit-dataprovider.git") | ||
url.set("scm:git@github.com:TNG/junit-dataprovider.git") | ||
} | ||
|
||
withXml { | ||
fun NodeList.asElementList() = (0 until length).map { this::item }.filterIsInstance<Element>() | ||
fun NodeList.onlyElement() = if (length == 1) item(0) else throw IllegalStateException("Expected only one element but got $length.") | ||
|
||
asElement() | ||
.getElementsByTagName("dependencies") | ||
.asElementList() | ||
.flatMap { it.childNodes.asElementList() } | ||
.forEach { dep -> | ||
val groupId = dep.getElementsByTagName("groupId").onlyElement() | ||
val artifactId = dep.getElementsByTagName("artifactId").onlyElement() | ||
|
||
// JUnit4 | ||
if (groupId.textContent == "junit" && artifactId.textContent == "junit") { | ||
dep.getElementsByTagName("version").onlyElement().textContent = "[4.10,4.12]" | ||
dep.getElementsByTagName("scope").onlyElement().textContent = "provided" | ||
} | ||
|
||
// JUnit5 | ||
if ((groupId.textContent == "org.junit.jupiter" && artifactId.textContent == "junit-jupiter-engine") || | ||
(groupId.textContent == "org.junit.jupiter" && artifactId.textContent == "junit-jupiter-params")) { | ||
dep.getElementsByTagName("version").onlyElement().textContent = "[5.5.0-M6,6.0.0)" | ||
dep.getElementsByTagName("scope").onlyElement().textContent = "provided" | ||
} | ||
} | ||
} | ||
} | ||
// finally call `asNode` to get rid of excessive newlines caused by use of asElement | ||
// see also https://github.com/gradle/gradle/issues/7529 | ||
afterEvaluate { | ||
pom { | ||
withXml { | ||
asNode() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") | ||
val snapshotRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/") | ||
url = if (isReleaseVersion) releasesRepoUrl else snapshotRepoUrl | ||
|
||
credentials { | ||
username = sonatypeUsername | ||
password = sonatypePassword | ||
} | ||
|
||
metadataSources { | ||
gradleMetadata() | ||
} | ||
} | ||
} | ||
} | ||
|
||
// requires gradle.properties, see http://www.gradle.org/docs/current/userguide/signing_plugin.html | ||
configure<SigningExtension> { | ||
setRequired({ isReleaseVersion && gradle.taskGraph.hasTask("publish") }) | ||
sign(the<PublishingExtension>().publications["mavenJava"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
plugins { | ||
groovy | ||
} | ||
|
||
val isBuildOnJenkins: Boolean by rootProject.extra | ||
val deps: Dependencies by rootProject.extra | ||
|
||
sourceSets { | ||
register("integTest") { | ||
compileClasspath += named("main").get().output | ||
runtimeClasspath += named("main").get().output | ||
} | ||
} | ||
|
||
configurations { | ||
"integTestImplementation" { | ||
extendsFrom(configurations["testImplementation"]) | ||
} | ||
} | ||
|
||
dependencies { | ||
"integTestImplementation"(deps.groovy) | ||
} | ||
|
||
tasks { | ||
val integTest = register<Test>("integTest") { | ||
group = "verification" | ||
description = "Runs all integration tests." | ||
|
||
ignoreFailures = isBuildOnJenkins | ||
|
||
classpath = sourceSets["integTest"].runtimeClasspath | ||
testClassesDirs = sourceSets["integTest"].output.classesDirs | ||
|
||
dependsOn(named("integTestClasses")) | ||
} | ||
|
||
val touchIntegTestResultsForJenkins = register<TouchTestResults>("touchIntegTestResultsForJenkins") { | ||
tasks(integTest) | ||
enabled = isBuildOnJenkins | ||
} | ||
|
||
named("build") { | ||
dependsOn(touchIntegTestResultsForJenkins) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
plugins { | ||
`dataprovider-library` | ||
} | ||
|
||
val deps: Dependencies by rootProject.extra | ||
|
||
base { | ||
archivesBaseName = "junit-dataprovider-core" | ||
description = "The common core for a TestNG like dataprovider runner for JUnit." | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_6 | ||
targetCompatibility = JavaVersion.VERSION_1_6 | ||
} | ||
|
||
dependencies { | ||
"testImplementation"(deps.junit4) | ||
|
||
"testImplementation"(deps.assertJ6) | ||
"testImplementation"(deps.mockito6) | ||
} | ||
|
||
tasks { | ||
withType<JavaCompile> { | ||
options.compilerArgs.addAll(listOf("-Xlint:-options")) | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes( | ||
"Automatic-Module-Name" to "com.tngtech.junit.dataprovider.core" | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
plugins { | ||
`dataprovider-library` | ||
`integration-test` | ||
} | ||
|
||
val deps: Dependencies by rootProject.extra | ||
|
||
base { | ||
archivesBaseName = "junit-jupiter-params-dataprovider" | ||
description = "A TestNG like dataprovider runner for JUnit Jupiter Parameterized Tests which is largely compatible to JUnit4 dataprovider." | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
dependencies { | ||
"api"(project(":core")) | ||
"api"(deps.junitJupiterEngine) | ||
"api"(deps.junitJupiterParams) | ||
|
||
"testImplementation"(deps.assertJ8) | ||
"testImplementation"(deps.mockito8) | ||
} | ||
|
||
tasks { | ||
withType<JavaCompile> { | ||
options.compilerArgs.addAll(listOf("-parameters")) | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes( | ||
"Automatic-Module-Name" to "com.tngtech.junit.dataprovider.jupiter.params" | ||
) | ||
} | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
} |
Oops, something went wrong.