|
1 | | -apply from: 'build.shared' |
2 | | -apply plugin: 'checkstyle' |
3 | | -apply plugin: 'jacoco' |
| 1 | +plugins { |
| 2 | + id 'java' |
| 3 | + id 'checkstyle' |
| 4 | + id 'jacoco' |
| 5 | + id 'maven-publish' |
| 6 | + id 'signing' |
| 7 | +} |
| 8 | + |
| 9 | +java { |
| 10 | + toolchain { |
| 11 | + languageVersion = JavaLanguageVersion.of(25) |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +repositories { |
| 16 | + mavenCentral() |
| 17 | +} |
| 18 | + |
| 19 | +dependencies { |
| 20 | + testImplementation 'junit:junit:4.13.2' |
| 21 | + implementation "org.threadly:threadly:$threadlyVersion" |
| 22 | +} |
| 23 | + |
| 24 | +compileJava { |
| 25 | + options.compilerArgs << '-Xlint:all' << '-Xlint:-deprecation' << '-Xlint:-this-escape' << '-Werror' |
| 26 | +} |
| 27 | + |
| 28 | +compileTestJava { |
| 29 | + options.compilerArgs << '-Xlint:all' |
| 30 | +} |
4 | 31 |
|
5 | | -plugins.withType(JavaPlugin) { |
6 | | - checkstyle.sourceSets = [sourceSets.main] |
| 32 | +checkstyle { |
| 33 | + sourceSets = [sourceSets.main] |
7 | 34 | } |
8 | 35 |
|
| 36 | +def testMode = project.findProperty('testMode') ?: 'default' |
| 37 | + |
9 | 38 | test { |
10 | | - maxParallelForks = Math.min(8, Math.max(1, (int)(Runtime.getRuntime().availableProcessors() / 4))) |
| 39 | + switch (testMode) { |
| 40 | + case 'slow': |
| 41 | + maxParallelForks = 1 |
| 42 | + systemProperty 'systemSpeed', 'slow' |
| 43 | + break |
| 44 | + case 'stress': |
| 45 | + systemProperty 'systemSpeed', 'slow' |
| 46 | + systemProperty 'testProfile', 'stress' |
| 47 | + maxParallelForks = Math.min(8, Math.max(1, (int)(Runtime.getRuntime().availableProcessors() / 2))) |
| 48 | + break |
| 49 | + default: |
| 50 | + maxParallelForks = Math.min(8, Math.max(1, (int)(Runtime.getRuntime().availableProcessors() / 4))) |
| 51 | + break |
| 52 | + } |
| 53 | + |
| 54 | + reports { |
| 55 | + junitXml.outputLocation = layout.buildDirectory.dir('reports/tests/xml') |
| 56 | + html.outputLocation = layout.buildDirectory.dir('reports/tests/html') |
| 57 | + } |
| 58 | + binaryResultsDirectory = layout.buildDirectory.dir('reports/tests/bin') |
| 59 | + |
11 | 60 | jacoco { |
12 | | - excludes = ['**/package-info**','**/*Test'] |
13 | | - destinationFile = file("$buildDir/reports/jacoco/test.exec") |
| 61 | + excludes = ['**/package-info**', '**/*Test'] |
| 62 | + destinationFile = layout.buildDirectory.file('reports/jacoco/test.exec').get().asFile |
14 | 63 | } |
15 | 64 | } |
16 | 65 |
|
17 | | -test.dependsOn("jar") |
| 66 | +test.dependsOn('jar') |
| 67 | + |
| 68 | +jar { |
| 69 | + manifest { |
| 70 | + attributes( |
| 71 | + 'Implementation-Title': 'Threadly Test Utilities', |
| 72 | + 'Implementation-Version': archiveVersion.get() |
| 73 | + ) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +javadoc { |
| 78 | + source = sourceSets.main.allJava |
| 79 | + excludes = ['**/ThreadlyInternalAccessor**', '**/ArgumentVerifier**'] |
| 80 | + options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC |
| 81 | +} |
| 82 | + |
| 83 | +tasks.register('javadocJar', Jar) { |
| 84 | + dependsOn javadoc |
| 85 | + archiveClassifier.set('javadoc') |
| 86 | + from javadoc.destinationDir |
| 87 | +} |
| 88 | + |
| 89 | +tasks.register('sourcesJar', Jar) { |
| 90 | + from sourceSets.main.allSource |
| 91 | + archiveClassifier.set('sources') |
| 92 | +} |
| 93 | + |
| 94 | +tasks.register('copyLibs', Copy) { |
| 95 | + into layout.buildDirectory.dir('dependencies') |
| 96 | + from configurations.runtimeClasspath |
| 97 | +} |
| 98 | + |
| 99 | +build.finalizedBy('copyLibs') |
18 | 100 |
|
19 | 101 | jacocoTestReport { |
20 | 102 | reports { |
21 | 103 | csv.required = false |
22 | 104 | xml.required = true |
23 | | - xml.destination = file("$buildDir/reports/jacoco/jacoco.xml") |
| 105 | + xml.outputLocation = layout.buildDirectory.file('reports/jacoco/jacoco.xml') |
24 | 106 | html.required = true |
25 | | - html.destination = file("$buildDir/reports/jacoco/html") |
| 107 | + html.outputLocation = layout.buildDirectory.dir('reports/jacoco/html') |
26 | 108 | } |
27 | 109 | doLast { |
28 | 110 | println "Test results available at:" |
29 | | - println "html - $buildDir/reports/tests/html/index.html" |
| 111 | + println "html - ${layout.buildDirectory.dir('reports/tests/html').get().asFile}/index.html" |
30 | 112 | println "Test coverage reports available at:" |
31 | | - println "html - $buildDir/reports/jacoco/html/index.html" |
| 113 | + println "html - ${layout.buildDirectory.dir('reports/jacoco/html').get().asFile}/index.html" |
32 | 114 | } |
33 | 115 | } |
34 | 116 |
|
35 | | -test.finalizedBy("jacocoTestReport") |
| 117 | +test.finalizedBy('jacocoTestReport') |
36 | 118 |
|
37 | 119 | jacocoTestCoverageVerification { |
38 | 120 | violationRules { |
@@ -63,4 +145,68 @@ jacocoTestCoverageVerification { |
63 | 145 | } |
64 | 146 | } |
65 | 147 |
|
66 | | -jacocoTestReport.finalizedBy("jacocoTestCoverageVerification") |
| 148 | +jacocoTestReport.finalizedBy('jacocoTestCoverageVerification') |
| 149 | + |
| 150 | +publishing { |
| 151 | + publications { |
| 152 | + mavenJava(MavenPublication) { |
| 153 | + from components.java |
| 154 | + |
| 155 | + artifact(tasks.named('sourcesJar')) |
| 156 | + artifact(tasks.named('javadocJar')) |
| 157 | + |
| 158 | + pom { |
| 159 | + name = 'Threadly Test Utilities' |
| 160 | + description = 'A library of tools to assist with testing concurrent java applications.' |
| 161 | + url = 'https://threadly.org/' |
| 162 | + |
| 163 | + scm { |
| 164 | + url = 'scm:git@github.com:threadly/threadly-test.git' |
| 165 | + connection = 'scm:git@github.com:threadly/threadly-test.git' |
| 166 | + developerConnection = 'scm:git@github.com:threadly/threadly-test.git' |
| 167 | + } |
| 168 | + |
| 169 | + issueManagement { |
| 170 | + system = 'GitHub' |
| 171 | + url = 'https://github.com/threadly/threadly-test/issues' |
| 172 | + } |
| 173 | + |
| 174 | + licenses { |
| 175 | + license { |
| 176 | + name = 'Mozilla Public License Version 2.0' |
| 177 | + url = 'https://www.mozilla.org/MPL/2.0/' |
| 178 | + distribution = 'repo' |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + developers { |
| 183 | + developer { |
| 184 | + id = 'jent' |
| 185 | + name = 'Mike Jensen' |
| 186 | + email = 'jent@threadly.org' |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + repositories { |
| 193 | + maven { |
| 194 | + def releasesRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' |
| 195 | + def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots' |
| 196 | + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl |
| 197 | + credentials { |
| 198 | + username = findProperty('sonatypeUsername') ?: '' |
| 199 | + password = findProperty('sonatypePassword') ?: '' |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +tasks.withType(GenerateMavenPom).configureEach { |
| 206 | + destination = layout.buildDirectory.file('generated-pom.xml').get().asFile |
| 207 | +} |
| 208 | + |
| 209 | +signing { |
| 210 | + required = { !version.toString().contains('SNAPSHOT') && gradle.taskGraph.hasTask('publish') } |
| 211 | + sign publishing.publications.mavenJava |
| 212 | +} |
0 commit comments