Skip to content

Commit 8418acb

Browse files
committed
publish task
1 parent 775d2fb commit 8418acb

File tree

3 files changed

+212
-77
lines changed

3 files changed

+212
-77
lines changed

build.gradle

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,40 @@
11
plugins {
22
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
33
id 'jacoco'
4+
id 'com.gradle.build-scan' version '1.16'
5+
id 'maven-publish'
6+
id 'signing'
7+
}
8+
9+
ext {
10+
publishBuildScan = false
11+
snapshotVersion = true
412
}
513

614
group 'com.nfeld.jsonpathlite'
7-
version '1.0.0-alpha01'
15+
version = '1.0.0' + (snapshotVersion ? "-SNAPSHOT" : "")
816

917
repositories {
10-
mavenCentral()
18+
jcenter()
1119
}
1220

1321
dependencies {
1422
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
1523
implementation "org.json:json:20180813"
16-
17-
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.0'
18-
testImplementation 'com.jayway.jsonpath:json-path:2.4.0'
1924
}
2025

2126
compileKotlin {
2227
kotlinOptions.jvmTarget = "1.8"
2328
}
24-
compileTestKotlin {
25-
kotlinOptions.jvmTarget = "1.8"
26-
}
27-
28-
test {
29-
// Make this task never up to date, thus forcing rerun of all tests whenever task is run
30-
outputs.upToDateWhen { false }
31-
32-
// enable junit 5
33-
useJUnitPlatform()
34-
35-
testLogging {
36-
// show test results for following events
37-
events 'PASSED', 'FAILED', 'SKIPPED'
38-
39-
// show printlines
40-
showStandardStreams = true
41-
}
4229

43-
// show test summary at end
44-
afterSuite { desc, result ->
45-
if (!desc.parent) {
46-
println "\nTest result: ${result.resultType}"
47-
println "Test summary: ${result.testCount} tests, " +
48-
"${result.successfulTestCount} succeeded, " +
49-
"${result.failedTestCount} failed, " +
50-
"${result.skippedTestCount} skipped"
51-
}
52-
}
53-
54-
// code coverage
55-
jacoco {
56-
append = false
57-
destinationFile = file("$buildDir/jacoco/junitPlatformTest.exec")
58-
includeNoLocationClasses = true
59-
}
60-
61-
finalizedBy jacocoTestReport
62-
}
63-
64-
jacoco {
65-
toolVersion = "0.8.3"
66-
reportsDir = file("$buildDir/reports")
67-
}
68-
jacocoTestReport {
69-
group = "Reporting"
70-
description = "Generate Jacoco coverage report."
71-
classDirectories = fileTree(
72-
dir: "$buildDir/classes/kotlin/main"
73-
)
74-
def coverageSourceDirs = [
75-
"src/main/kotlin"
76-
]
77-
additionalSourceDirs = files(coverageSourceDirs)
78-
sourceDirectories = files(coverageSourceDirs)
79-
executionData = files("$buildDir/jacoco/junitPlatformTest.exec")
80-
reports {
81-
xml.enabled = true
82-
html.enabled = true
83-
csv.enabled = false
84-
}
85-
}
30+
apply from: "tests_codecov.gradle"
31+
apply from: "publish.gradle"
8632

87-
check.dependsOn jacocoTestCoverageVerification
33+
buildScan {
34+
termsOfServiceUrl = "https://gradle.com/terms-of-service"
35+
termsOfServiceAgree = "yes"
8836

89-
jacocoTestCoverageVerification {
90-
violationRules {
91-
rule {
92-
// element = 'CLASS'
93-
limit {
94-
counter = 'LINE'
95-
value = 'COVEREDRATIO'
96-
minimum = 0.95
97-
}
98-
}
37+
if (publishBuildScan) {
38+
publishAlways()
9939
}
10040
}

publish.gradle

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
def publishLocal = true
3+
4+
task sourceJar(type: Jar) {
5+
classifier "sources"
6+
from sourceSets.main.allSource
7+
}
8+
9+
//task javadocJar(type: Jar, dependsOn: javadoc) {
10+
// classifier "javadoc"
11+
// from javadoc.destinationDir
12+
//}
13+
14+
publishing {
15+
publications {
16+
mavenJava(MavenPublication) {
17+
from components.java
18+
19+
artifact(sourceJar) {
20+
classifier = 'sources'
21+
}
22+
// artifact(javadocJar) {
23+
// classifier = 'javadoc'
24+
// }
25+
26+
pom {
27+
name = 'JsonPathLite'
28+
description = '2019 refresh of Jayway\'s JsonPath with goals to be lighter in size and have better performance.'
29+
url = 'https://github.com/codeniko/JsonPathLite'
30+
licenses {
31+
license {
32+
name = 'BSD-3-Clause'
33+
url = 'https://github.com/codeniko/JsonPathLite/blob/master/LICENSE'
34+
}
35+
}
36+
developers {
37+
developer {
38+
id = 'codeniko'
39+
name = 'Nikolay Feldman'
40+
}
41+
}
42+
scm {
43+
connection = 'scm:git:git://github.com/codeniko/JsonPathLite.git'
44+
developerConnection = 'scm:git:ssh://[email protected]:codeniko/JsonPathLite.git'
45+
url = 'https://github.com/codeniko/JsonPathLite'
46+
}
47+
}
48+
49+
if (!publishLocal) {
50+
// create the sign pom artifact
51+
pom.withXml {
52+
def pomFile = file("${project.buildDir}/generated-pom.xml")
53+
writeTo(pomFile)
54+
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
55+
artifact(pomAscFile) {
56+
classifier = null
57+
extension = 'pom.asc'
58+
}
59+
}
60+
// create the signed artifacts
61+
project.tasks.signArchives.signatureFiles.each {
62+
artifact(it) {
63+
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
64+
if (matcher.find()) {
65+
classifier = matcher.group(1)
66+
} else {
67+
classifier = null
68+
}
69+
extension = 'jar.asc'
70+
}
71+
}
72+
}
73+
}
74+
}
75+
76+
repositories {
77+
maven {
78+
if (publishLocal) {
79+
// publish to local repo
80+
url = uri("$buildDir/repository")
81+
} else {
82+
url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
83+
credentials {
84+
username sonatypeUsername
85+
password sonatypePassword
86+
}
87+
}
88+
}
89+
}
90+
}
91+
92+
model {
93+
tasks.generatePomFileForMavenJavaPublication {
94+
destination = file("$buildDir/generated-pom.xml")
95+
}
96+
97+
}
98+
if (!publishLocal) {
99+
model {
100+
tasks.publishMavenJavaPublicationToMavenLocal {
101+
dependsOn project.tasks.signArchives
102+
}
103+
tasks.publishMavenJavaPublicationToMavenRepository {
104+
dependsOn project.tasks.signArchives
105+
}
106+
}
107+
}
108+
109+
signing {
110+
required { !snapshotVersion }
111+
sign configurations.archives
112+
}

tests_codecov.gradle

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
dependencies {
2+
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.0'
3+
testImplementation 'com.jayway.jsonpath:json-path:2.4.0'
4+
}
5+
6+
compileTestKotlin {
7+
kotlinOptions.jvmTarget = "1.8"
8+
}
9+
10+
test {
11+
// Make this task never up to date, thus forcing rerun of all tests whenever task is run
12+
outputs.upToDateWhen { false }
13+
14+
// enable junit 5
15+
useJUnitPlatform()
16+
17+
testLogging {
18+
// show test results for following events
19+
events 'PASSED', 'FAILED', 'SKIPPED'
20+
21+
// show printlines
22+
showStandardStreams = true
23+
}
24+
25+
// show test summary at end
26+
afterSuite { desc, result ->
27+
if (!desc.parent) {
28+
println "\nTest result: ${result.resultType}"
29+
println "Test summary: ${result.testCount} tests, " +
30+
"${result.successfulTestCount} succeeded, " +
31+
"${result.failedTestCount} failed, " +
32+
"${result.skippedTestCount} skipped"
33+
}
34+
}
35+
36+
// code coverage
37+
jacoco {
38+
append = false
39+
destinationFile = file("$buildDir/jacoco/junitPlatformTest.exec")
40+
includeNoLocationClasses = true
41+
}
42+
43+
finalizedBy jacocoTestReport
44+
}
45+
46+
jacoco {
47+
toolVersion = "0.8.3"
48+
reportsDir = file("$buildDir/reports")
49+
}
50+
51+
jacocoTestReport {
52+
group = "Reporting"
53+
description = "Generate Jacoco coverage report."
54+
classDirectories = fileTree(
55+
dir: "$buildDir/classes/kotlin/main"
56+
)
57+
def coverageSourceDirs = [
58+
"src/main/kotlin"
59+
]
60+
additionalSourceDirs = files(coverageSourceDirs)
61+
sourceDirectories = files(coverageSourceDirs)
62+
executionData = files("$buildDir/jacoco/junitPlatformTest.exec")
63+
reports {
64+
xml.enabled = true
65+
html.enabled = true
66+
csv.enabled = false
67+
}
68+
}
69+
70+
check.dependsOn jacocoTestCoverageVerification
71+
72+
jacocoTestCoverageVerification {
73+
violationRules {
74+
rule {
75+
// element = 'CLASS'
76+
limit {
77+
counter = 'LINE'
78+
value = 'COVEREDRATIO'
79+
minimum = 0.95
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)