Skip to content

Commit 9c4d6d0

Browse files
committed
Add initial build configuration
Based on threadly's files, this configuration depends on threadly 5.42
1 parent 6aba222 commit 9c4d6d0

File tree

6 files changed

+275
-0
lines changed

6 files changed

+275
-0
lines changed

build.gradle

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
apply from: 'build.shared'
2+
apply plugin: 'checkstyle'
3+
apply plugin: 'jacoco'
4+
5+
plugins.withType(JavaPlugin) {
6+
checkstyle.sourceSets = [sourceSets.main]
7+
}
8+
9+
test {
10+
maxParallelForks = Math.min(8, Math.max(1, (int)(Runtime.getRuntime().availableProcessors() / 4)))
11+
jacoco {
12+
excludes = ['**/package-info**','**/*Test']
13+
destinationFile = file("$buildDir/reports/jacoco/test.exec")
14+
}
15+
}
16+
17+
build.dependsOn jacocoTestReport
18+
19+
jacocoTestReport {
20+
reports {
21+
csv.enabled = false
22+
xml.enabled = true
23+
xml.destination = file("$buildDir/reports/jacoco/jacoco.xml")
24+
html.enabled = true
25+
html.destination = file("$buildDir/reports/jacoco/html")
26+
}
27+
doLast {
28+
println "Test results available at:"
29+
println "html - $buildDir/reports/tests/html/index.html"
30+
println "Test coverage reports available at:"
31+
println "html - $buildDir/reports/jacoco/html/index.html"
32+
}
33+
}
34+
35+
jacocoTestCoverageVerification {
36+
violationRules {
37+
rule {
38+
limit {
39+
counter = 'METHOD'
40+
minimum = 0.9
41+
}
42+
}
43+
rule {
44+
limit {
45+
counter = 'CLASS'
46+
minimum = 0.9
47+
}
48+
}
49+
rule {
50+
limit {
51+
counter = 'LINE'
52+
minimum = 0.9
53+
}
54+
}
55+
rule {
56+
limit {
57+
counter = 'BRANCH'
58+
minimum = 0.8
59+
}
60+
}
61+
}
62+
}
63+
64+
check.dependsOn jacocoTestCoverageVerification

build.shared

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apply plugin: 'java'
2+
3+
repositories {
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
testImplementation (
9+
"junit:junit:4.12",
10+
)
11+
12+
implementation (
13+
"org.threadly:threadly:$threadlyVersion"
14+
)
15+
}
16+
17+
compileJava {
18+
options.compilerArgs << "-Xlint:all" << "-Xlint:-deprecation" << "-Werror"
19+
20+
if (JavaVersion.current().isJava8()) {
21+
options.compilerArgs << "-XDenableSunApiLintControl" << "-Xlint:-sunapi"
22+
}
23+
}
24+
25+
compileTestJava {
26+
options.compilerArgs << "-Xlint:all"
27+
}
28+
29+
test {
30+
getReports().getJunitXml().setDestination(file("$buildDir/reports/tests/xml"))
31+
getReports().getHtml().setDestination(file("$buildDir/reports/tests/html"))
32+
setBinResultsDir(file("$buildDir/reports/tests/bin"))
33+
}
34+
35+
jar {
36+
manifest {
37+
attributes (
38+
'Implementation-Title': 'Threadly Test Utilities',
39+
'Implementation-Version': archiveVersion
40+
)
41+
}
42+
}
43+
44+
javadoc {
45+
source = sourceSets.main.allJava
46+
excludes = ['**/ThreadlyInternalAccessor**', '**/ArgumentVerifier**']
47+
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC
48+
}
49+
50+
task javadocJar(type: Jar, dependsOn: javadoc) {
51+
classifier = 'javadoc'
52+
from 'build/docs/javadoc'
53+
}
54+
55+
task sourcesJar(type: Jar) {
56+
from sourceSets.main.allSource
57+
classifier = 'sources'
58+
}
59+
60+
build.dependsOn("copyLibs");
61+
62+
task copyLibs(type: Copy) {
63+
into "$buildDir/dependencies/"
64+
from configurations.runtimeClasspath
65+
}
66+
67+
artifacts {
68+
//archives jar // already specified by default
69+
archives javadocJar
70+
archives sourcesJar
71+
}

build.slow

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apply from: 'build.gradle'
2+
apply plugin: 'jacoco'
3+
4+
test {
5+
maxParallelForks = 1
6+
systemProperty 'systemSpeed', 'slow'
7+
}

build.stress

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apply from: 'build.gradle'
2+
apply plugin: 'jacoco'
3+
4+
test {
5+
systemProperty 'systemSpeed', 'slow'
6+
systemProperty 'testProfile', 'stress'
7+
maxParallelForks = Math.min(8, Math.max(1, (int)(Runtime.getRuntime().availableProcessors() / 2)))
8+
}

build.upload

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
apply from: 'build.shared'
2+
apply plugin: 'maven-publish'
3+
apply plugin: 'signing'
4+
5+
sourceCompatibility = 1.8
6+
targetCompatibility = 1.8
7+
8+
test {
9+
maxParallelForks = Math.max(1, (int)(Runtime.getRuntime().availableProcessors() / 2))
10+
}
11+
12+
def findJVM() {
13+
String[] java8Paths = new String[5]
14+
java8Paths[0] = "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/"
15+
java8Paths[1] = "/usr/lib/jvm/java-8-openjdk/jre/lib/"
16+
java8Paths[2] = "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/"
17+
java8Paths[3] = "/usr/lib/jvm/java-1.8.0-openjdk/jre/lib/"
18+
java8Paths[4] = "/usr/lib/jvm/java-8-sun/jre/lib/"
19+
for (String path : java8Paths) {
20+
if (new java.io.File(path).exists()) {
21+
return path
22+
}
23+
}
24+
return null
25+
}
26+
27+
compileJava {
28+
def jvmPath = findJVM()
29+
if (jvmPath == null) {
30+
println 'Unable to find java 8 rt.jar, will cause failure so exiting now'
31+
println ''
32+
System.exit(1)
33+
}
34+
println 'Using java 8: ' + jvmPath
35+
options.bootstrapClasspath = fileTree(include: ['*.jar'], dir: jvmPath)
36+
}
37+
38+
compileTestJava {
39+
options.compilerArgs << "-Xlint:all" << "-Xlint:-deprecation" << "-Werror"
40+
41+
options.bootstrapClasspath = fileTree(include: ['*.jar'], dir: findJVM())
42+
}
43+
44+
signing {
45+
sign configurations.archives
46+
if (! version.contains('SNAPSHOT')) {
47+
sign publishing.publications
48+
}
49+
}
50+
51+
publishing {
52+
publications {
53+
mavenJava(MavenPublication) {
54+
pom {
55+
name = 'Threadly'
56+
description = 'A library of tools to assist with safe concurrent java development.'
57+
url = 'http://threadly.org/'
58+
59+
scm {
60+
url = 'scm:[email protected]:threadly/threadly.git'
61+
connection = 'scm:[email protected]:threadly/threadly.git'
62+
developerConnection = 'scm:[email protected]:threadly/threadly.git'
63+
}
64+
65+
issueManagement {
66+
system = 'GitHub'
67+
url = 'https://github.com/threadly/threadly/issues'
68+
}
69+
70+
licenses {
71+
license {
72+
name = 'Mozilla Public License Version 2.0'
73+
url = 'https://www.mozilla.org/MPL/2.0/'
74+
distribution = 'repo'
75+
}
76+
}
77+
78+
developers {
79+
developer {
80+
id = 'jent'
81+
name = 'Mike Jensen'
82+
83+
}
84+
}
85+
}
86+
87+
from components.java
88+
89+
artifact(sourcesJar) {
90+
classifier = 'sources'
91+
}
92+
artifact(javadocJar) {
93+
classifier = 'javadoc'
94+
}
95+
}
96+
}
97+
repositories {
98+
maven {
99+
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
100+
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
101+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
102+
credentials {
103+
username sonatypeUsername
104+
password sonatypePassword
105+
}
106+
}
107+
}
108+
}
109+
110+
model {
111+
tasks.generatePomFileForMavenJavaPublication {
112+
destination = file("$buildDir/generated-pom.xml")
113+
}
114+
tasks.publishMavenJavaPublicationToMavenLocal {
115+
dependsOn project.tasks.signArchives
116+
}
117+
tasks.publishMavenJavaPublicationToMavenRepository {
118+
dependsOn project.tasks.signArchives
119+
}
120+
}

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
group = org.threadly
2+
version = 0.1-SNAPSHOT
3+
org.gradle.parallel = false
4+
5+
threadlyVersion = 5.42

0 commit comments

Comments
 (0)