-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
167 lines (142 loc) · 4.92 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import com.jfrog.bintray.gradle.BintrayExtension
import org.apache.xml.serialize.OutputFormat
import org.apache.xml.serialize.XMLSerializer
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.PublishArtifact
import org.gradle.api.artifacts.dsl.ArtifactHandler
import org.gradle.api.plugins.MavenPluginConvention
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar
import org.gradle.script.lang.kotlin.*
import org.gradle.testing.jacoco.tasks.JacocoReport
import org.w3c.dom.Document
import org.w3c.dom.Node
import java.io.StringWriter
import javax.xml.parsers.DocumentBuilderFactory
version = "v0.1.4"
buildscript {
repositories {
jcenter()
gradleScriptKotlin()
}
dependencies {
classpath(kotlinModule("gradle-plugin"))
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7")
}
}
repositories {
jcenter()
gradleScriptKotlin()
}
apply {
plugin("java")
plugin("maven")
plugin("jacoco")
plugin("com.jfrog.bintray")
}
setProperty("targetCompatibility", 1.7)
setProperty("sourceCompatibility", 1.7)
dependencies {
testCompile("junit:junit:4.12")
testCompile("nl.jqno.equalsverifier:equalsverifier:2.1.5")
}
val sourceSets = the<JavaPluginConvention>().sourceSets
val sourcesJar = task<Jar>("sourcesJars") {
dependsOn + "classes"
classifier = "sources"
from(sourceSets.getByName("main").allSource)
}
val javadoc = tasks.getByName("javadoc") as Javadoc
val javadocJar = task<Jar>("javadocJar") {
dependsOn + "javadoc"
classifier = "javadoc"
from(javadoc.destinationDir)
}
artifacts {
artifacts.add("archives", sourcesJar)
artifacts.add("archives", javadocJar)
}
(getTasksByName("jacocoTestReport", false).first() as JacocoReport).apply {
reports {
it.xml.isEnabled = true
}
}
configure<BintrayExtension> {
user = System.getenv("BINTRAY_USER")
key = System.getenv("BINTRAY_APIKEY")
setConfigurations("archives")
pkg.apply {
repo = "maven"
name = "retro-optional"
desc = "A backport of Java 8 optional for Java 7"
websiteUrl = "https://github.com/memoizr/retro-optional"
vcsUrl = "https://github.com/memoizr/retro-optional"
publish = true
publicDownloadNumbers = false
version.apply {
desc = "A backport of Java 8 optional for Java 7"
gpg.apply {
sign = true
passphrase = System.getenv("BINTRAY_CREDENTIAL")
}
}
}
}
val documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
task("createPom") {
doLast {
the<MavenPluginConvention>().pom().apply {
project.apply {
groupId = "com.memoizr"
artifactId = "retro-optional"
withXml {
val xml = it.asString()
val document: Document = documentBuilder.parse(xml.toString().byteInputStream())
document.append {
"licenses" {
"license" {
"name"("The Apache Software License, Version 2.0")
"url"("http://www.apache.org/licenses/LICENSE-2.0.txt")
"distribution"("repo")
}
}
}
val format = OutputFormat(document)
format.indenting = true
val writer = StringWriter()
val serializer = XMLSerializer(writer, format)
serializer.serialize(document)
xml.setLength(0)
xml.append(writer)
}
}
}.writeTo("build/poms/pom-default.xml")
}
}
class DocuBuilder(private val document: Document, private val parent: Node) {
operator fun String.invoke(content: DocuBuilder.() -> Unit) {
val element = document.createElement(this)
DocuBuilder(document, element).content()
parent.appendChild(element)
}
operator fun String.invoke(text: String) {
val element = document.createElement(this)
element.appendChild(document.createTextNode(text))
parent.appendChild(element)
}
}
fun Document.append(content: DocuBuilder.() -> Unit) {
DocuBuilder(this, firstChild).content()
}
inline fun Project.artifacts(configuration: KotlinArtifactsHandler.() -> Unit) =
KotlinArtifactsHandler(artifacts).configuration()
class KotlinArtifactsHandler(val artifacts: ArtifactHandler) : ArtifactHandler by artifacts {
operator fun String.invoke(dependencyNotation: Any): PublishArtifact =
artifacts.add(this, dependencyNotation)
inline operator fun invoke(configuration: KotlinArtifactsHandler.() -> Unit) =
configuration()
}
infix fun Task.doLast(task: org.gradle.api.Task.() -> kotlin.Unit) {
this.doLast(task)
}