|
| 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 | +} |
0 commit comments