Skip to content

Commit b62f52d

Browse files
committed
initial implementation of kotlin build file
1 parent 0d373d5 commit b62f52d

File tree

6 files changed

+150
-26
lines changed

6 files changed

+150
-26
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ install {
7575
}
7676
}
7777
}
78+
7879
apply plugin: 'com.jfrog.bintray'
7980

8081
Properties properties = new Properties()

build.gradle.kts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
import com.jfrog.bintray.gradle.BintrayExtension
3+
import org.gradle.api.Project
4+
import org.gradle.api.Task
5+
import org.gradle.api.artifacts.PublishArtifact
6+
import org.gradle.api.artifacts.dsl.ArtifactHandler
7+
import org.gradle.api.internal.tasks.DefaultSourceSetContainer
8+
import org.gradle.jvm.tasks.Jar
9+
import org.gradle.script.lang.kotlin.*
10+
import java.util.*
11+
import kotlin.properties.ReadOnlyProperty
12+
import kotlin.reflect.KProperty
13+
14+
class newTask(private val configuration: org.gradle.api.Task.() -> kotlin.Unit) : ReadOnlyProperty<KotlinBuildScript, Task> {
15+
private var task: Task? = null
16+
17+
override fun getValue(thisRef: KotlinBuildScript, property: KProperty<*>): Task {
18+
return task ?: getTask(thisRef, property)
19+
}
20+
21+
private fun getTask(thisRef: KotlinBuildScript, property: KProperty<*>): Task {
22+
val task = thisRef.task(property.name).doLast(configuration)
23+
this.task = task
24+
return task
25+
}
26+
}
27+
28+
version = "v0.1.4"
29+
30+
buildscript {
31+
repositories {
32+
jcenter()
33+
gradleScriptKotlin()
34+
}
35+
dependencies {
36+
classpath(kotlinModule("gradle-plugin"))
37+
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7")
38+
}
39+
}
40+
41+
repositories {
42+
jcenter()
43+
gradleScriptKotlin()
44+
}
45+
46+
apply {
47+
plugin("java")
48+
plugin("com.jfrog.bintray")
49+
}
50+
51+
dependencies {
52+
testCompile("junit:junit:4.12")
53+
}
54+
55+
val sourceSets by project
56+
val javadoc by project
57+
58+
val myproperties = Properties()
59+
myproperties.load(project.rootProject.file("local.properties").inputStream())
60+
61+
(findProperty("bintray") as BintrayExtension).apply {
62+
user = myproperties["bintray.user"] as String
63+
key = myproperties["bintray.apikey"] as String
64+
setConfigurations("archives")
65+
pkg.apply {
66+
repo = "maven"
67+
name = "retro-optional"
68+
desc = "A backport of Java 8 optional for Java 7"
69+
websiteUrl = "https://github.com/memoizr/retro-optional"
70+
vcsUrl = "https://github.com/memoizr/retro-optional"
71+
publish = true
72+
publicDownloadNumbers = false
73+
version.apply {
74+
desc = "A backport of Java 8 optional for Java 7"
75+
gpg.apply {
76+
sign = true
77+
passphrase = myproperties.getProperty("bintray.gpg.password")
78+
}
79+
}
80+
}
81+
}
82+
83+
with(extra) {
84+
set("bintrayRepo", "maven")
85+
set("bintrayName", "retro-optional")
86+
set("publishedGroupId", "com.memoizr")
87+
set("libraryName", "retro-optional")
88+
set("artifact", "retro-optional")
89+
set("libraryDescription", "A backport of Java 8 optional for Java 7")
90+
set("siteUrl", "https://github.com/memoizr/retro-optional")
91+
set("gitUrl", "https://github.com/memoizr/retro-optional")
92+
set("libraryVersion", "0.9.3")
93+
set("developerId", "memoizr")
94+
set("developerName", "memoizr")
95+
set("developerEmail", "memoizrlabs@gmail.com")
96+
set("licenseName", "The Apache Software License, Version 2.0")
97+
set("licenseUrl", "http://www.apache.org/licenses/LICENSE-2.0.txt")
98+
set("allLicenses", listOf("Apache-2.0"))
99+
}
100+
101+
setProperty("targetCompatibility", 1.7)
102+
setProperty("sourceCompatibility", 1.7)
103+
104+
val sourcesJar = task<Jar>("sourcesJars") {
105+
dependsOn + "classes"
106+
classifier = "sources"
107+
from((sourceSets as DefaultSourceSetContainer).getByName("main").allSource)
108+
}
109+
110+
val javadocJar = task<Jar>("javadocJar") {
111+
dependsOn + "javadoc"
112+
classifier = "javadoc"
113+
from(getTasksByName("javadoc", false).first().property("destinationDir"))
114+
}
115+
116+
artifacts {
117+
artifacts.add("archives", sourcesJar)
118+
artifacts.add("archives", javadocJar)
119+
}
120+
121+
122+
inline fun Project.artifacts(configuration: KotlinArtifactsHandler.() -> Unit) =
123+
KotlinArtifactsHandler(artifacts).configuration()
124+
125+
infix fun Task.doLast(task: org.gradle.api.Task.() -> kotlin.Unit) {
126+
this.doLast(task)
127+
}
128+
129+
fun defaultTasks(vararg property: KProperty<Task>) {
130+
defaultTasks(*property.map { it.name }.toTypedArray())
131+
}
132+
133+
javaClass.declaredMethods.forEach {
134+
if (it.returnType == Task::class.java && it.name.startsWith("get")) {
135+
it.invoke(this)
136+
}
137+
}
138+
139+
class KotlinArtifactsHandler(val artifacts: ArtifactHandler) : ArtifactHandler by artifacts {
140+
141+
operator fun String.invoke(dependencyNotation: Any): PublishArtifact =
142+
artifacts.add(this, dependencyNotation)
143+
144+
inline operator fun invoke(configuration: KotlinArtifactsHandler.() -> Unit) =
145+
configuration()
146+
}

gradle/wrapper/gradle-wrapper.jar

1.75 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Mon Nov 09 17:43:14 GMT 2015
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
zipStoreBase=GRADLE_USER_HOME
54
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
5+
distributionUrl=https\://repo.gradle.org/gradle/dist-snapshots/gradle-script-kotlin-3.0.0-20160805133427+0000-all.zip

pom.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
rootProject.name = 'RetroOptional'
1+
rootProject.name = 'retro-optional'
2+
rootProject.buildFileName = 'build.gradle.kts'
23

0 commit comments

Comments
 (0)