2021-04-11 18:15:58 +08:00
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
2021-08-13 21:23:48 +08:00
|
|
|
import java.util.*
|
2021-04-11 18:15:58 +08:00
|
|
|
|
|
|
|
ext["netty.version"] = "4.1.59.Final"
|
|
|
|
ext["excludeTest"] = { project: Project, tasks: TaskContainer ->
|
2021-07-10 12:04:11 +08:00
|
|
|
if (project.gradle.startParameter.taskNames.firstOrNull { taskName ->
|
2021-08-14 00:17:16 +08:00
|
|
|
":test" in taskName
|
2021-07-10 12:04:11 +08:00
|
|
|
} == null) {
|
|
|
|
tasks {
|
|
|
|
test { enabled = false }
|
|
|
|
testClasses { enabled = false }
|
|
|
|
compileTestJava { enabled = false }
|
|
|
|
compileTestKotlin { enabled = false }
|
|
|
|
processTestResources { enabled = false }
|
2021-04-11 18:15:58 +08:00
|
|
|
}
|
2021-07-10 12:04:11 +08:00
|
|
|
}
|
2021-04-11 18:15:58 +08:00
|
|
|
}
|
2021-08-13 21:23:48 +08:00
|
|
|
ext["publishRepositories"] = { project: Project, p: PublishingExtension ->
|
|
|
|
p.repositories {
|
2021-08-14 01:48:22 +08:00
|
|
|
try {
|
2021-08-17 17:48:11 +08:00
|
|
|
val artifactoryUser: String = rootProject.ext["tursom.artifactoryUser"] as String
|
|
|
|
val artifactoryPassword: String = rootProject.ext["tursom.artifactoryPassword"] as String
|
2021-08-14 01:48:22 +08:00
|
|
|
maven {
|
|
|
|
val releasesRepoUrl = uri("https://nvm.tursom.cn/repository/maven-releases/")
|
|
|
|
val snapshotRepoUrl = uri("https://nvm.tursom.cn/repository/maven-snapshots/")
|
|
|
|
url = if (project.version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else releasesRepoUrl
|
|
|
|
credentials {
|
|
|
|
username = artifactoryUser
|
|
|
|
password = artifactoryPassword
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
2021-08-19 15:43:52 +08:00
|
|
|
println("cannot push to repository tursom")
|
2021-08-14 01:48:22 +08:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
maven {
|
|
|
|
val githubUser: String by rootProject
|
|
|
|
val githubToken: String by rootProject
|
|
|
|
name = "GitHubPackages"
|
|
|
|
url = uri("https://maven.pkg.github.com/$githubUser/TursomServer")
|
|
|
|
credentials {
|
|
|
|
username = githubUser
|
|
|
|
password = githubToken
|
|
|
|
}
|
2021-08-13 21:23:48 +08:00
|
|
|
}
|
2021-08-14 01:48:22 +08:00
|
|
|
} catch (e: Exception) {
|
2021-08-19 15:43:52 +08:00
|
|
|
println("cannot push to repository github")
|
2021-08-17 17:48:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
val repositoriesRegex = "repositories\\.[a-zA-z]*".toRegex()
|
|
|
|
rootProject.properties.keys.asSequence().filter {
|
|
|
|
it matches repositoriesRegex
|
|
|
|
}.forEach {
|
|
|
|
val repositoryName = rootProject.ext.properties["$it.name"]?.toString() ?: it.substringAfterLast('.')
|
|
|
|
try {
|
|
|
|
val artifactoryUser = rootProject.ext.properties["$it.artifactoryUser"].toString()
|
|
|
|
val artifactoryPassword = rootProject.ext.properties["$it.artifactoryPassword"].toString()
|
|
|
|
maven {
|
|
|
|
name = repositoryName
|
|
|
|
val releasesRepoUrl = rootProject.ext.properties["$it.release"]?.let { uri(it.toString()) }
|
|
|
|
val snapshotRepoUrl = rootProject.ext.properties["$it.snapshot"]?.let { uri(it.toString()) }
|
|
|
|
val repoUrl = rootProject.ext.properties["$it.url"]?.let { uri(it.toString()) }
|
|
|
|
url = if (project.version.toString().endsWith("SNAPSHOT")
|
|
|
|
&& snapshotRepoUrl != null
|
|
|
|
) {
|
|
|
|
snapshotRepoUrl
|
|
|
|
} else releasesRepoUrl ?: repoUrl!!
|
|
|
|
credentials {
|
|
|
|
username = artifactoryUser
|
|
|
|
password = artifactoryPassword
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
2021-08-19 15:43:52 +08:00
|
|
|
println("cannot push to repository $repositoryName")
|
2021-08-17 17:48:11 +08:00
|
|
|
}
|
2021-08-13 21:23:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-11 18:15:58 +08:00
|
|
|
|
2021-08-13 21:23:48 +08:00
|
|
|
try {
|
|
|
|
val properties = Properties()
|
|
|
|
properties.load(rootProject.file("local.properties").inputStream())
|
|
|
|
properties.forEach { (k, v) ->
|
|
|
|
rootProject.ext.set(k.toString(), v)
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
}
|
2021-04-11 18:15:58 +08:00
|
|
|
|
|
|
|
plugins {
|
2021-07-16 00:33:42 +08:00
|
|
|
kotlin("jvm") version "1.5.21"
|
2021-07-10 12:04:11 +08:00
|
|
|
`maven-publish`
|
2021-04-11 18:15:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
2021-07-10 12:04:11 +08:00
|
|
|
group = "cn.tursom"
|
2021-08-14 01:48:22 +08:00
|
|
|
version = "1.0-SNAPSHOT"
|
2021-04-11 18:15:58 +08:00
|
|
|
|
2021-07-10 12:04:11 +08:00
|
|
|
repositories {
|
2021-08-14 00:17:16 +08:00
|
|
|
// mavenLocal()
|
2021-08-14 01:48:22 +08:00
|
|
|
mavenCentral()
|
2021-08-14 00:17:16 +08:00
|
|
|
maven {
|
|
|
|
url = uri("https://nvm.tursom.cn/repository/maven-public/")
|
|
|
|
}
|
2021-07-10 12:04:11 +08:00
|
|
|
}
|
2021-04-11 18:15:58 +08:00
|
|
|
|
2021-07-10 12:04:11 +08:00
|
|
|
tasks.withType<JavaCompile> {
|
|
|
|
tasks.withType<KotlinCompile>().configureEach {
|
|
|
|
kotlinOptions.jvmTarget = "1.8"
|
|
|
|
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
|
2021-04-11 18:15:58 +08:00
|
|
|
}
|
2021-04-19 16:19:35 +08:00
|
|
|
|
2021-07-10 12:04:11 +08:00
|
|
|
if (project.gradle.startParameter.taskNames.firstOrNull { taskName ->
|
|
|
|
taskName.endsWith(":test")
|
|
|
|
} == null) {
|
|
|
|
tasks.withType<Test> {
|
|
|
|
enabled = false
|
|
|
|
}
|
2021-04-19 16:19:35 +08:00
|
|
|
}
|
2021-07-10 12:04:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType<KotlinCompile>().configureEach {
|
|
|
|
kotlinOptions.jvmTarget = "1.8"
|
|
|
|
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
|
|
|
|
//kotlinOptions.useIR = true
|
|
|
|
}
|
2021-04-11 18:15:58 +08:00
|
|
|
}
|
|
|
|
|
2021-08-13 21:23:48 +08:00
|
|
|
@Suppress("UNCHECKED_CAST")
|
2021-04-11 18:15:58 +08:00
|
|
|
(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks)
|
|
|
|
|
|
|
|
dependencies {
|
2021-08-18 17:37:19 +08:00
|
|
|
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21")
|
|
|
|
api("org.jetbrains.kotlin:kotlin-reflect:1.5.21")
|
|
|
|
testImplementation(group = "junit", name = "junit", version = "4.13.2")
|
2021-04-11 18:15:58 +08:00
|
|
|
}
|
2021-04-11 18:48:18 +08:00
|
|
|
|
2021-04-19 16:19:35 +08:00
|
|
|
artifacts {
|
2021-07-10 12:04:11 +08:00
|
|
|
archives(tasks["kotlinSourcesJar"])
|
2021-04-19 16:19:35 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 18:48:18 +08:00
|
|
|
tasks.register("install") {
|
2021-07-10 12:04:11 +08:00
|
|
|
finalizedBy(tasks["publishToMavenLocal"])
|
2021-04-11 18:48:18 +08:00
|
|
|
}
|
|
|
|
|
2021-08-14 01:48:22 +08:00
|
|
|
//publishing {
|
|
|
|
// @Suppress("UNCHECKED_CAST")
|
|
|
|
// (rootProject.ext["publishRepositories"] as (Project, PublishingExtension) -> Unit)(project, this)
|
|
|
|
// publications {
|
|
|
|
// create<MavenPublication>("maven") {
|
|
|
|
// groupId = project.group.toString()
|
|
|
|
// artifactId = project.name
|
|
|
|
// version = project.version.toString()
|
|
|
|
//
|
|
|
|
// from(components["java"])
|
|
|
|
// try {
|
|
|
|
// artifact(tasks["kotlinSourcesJar"])
|
|
|
|
// } catch (e: Exception) {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|