update gradle build scripts

This commit is contained in:
tursom 2023-10-27 18:11:28 +08:00
parent 2cd4d0353b
commit 1613393381
55 changed files with 320 additions and 362 deletions

View File

@ -1,31 +1,39 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.20-RC2"
id("ts-gradle")
val kotlinVersion = "1.9.20-RC2"
kotlin("jvm") version kotlinVersion
kotlin("plugin.allopen") version kotlinVersion apply false
id("ts-gradle-env") apply false
id("ts-gradle-install") apply false
id("ts-gradle-no-test") apply false
id("ts-gradle-publish") apply false
id("ts-gradle-repos") apply false
}
allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "maven-publish")
apply(plugin = "ts-gradle-env")
apply(plugin = "ts-gradle-install")
apply(plugin = "ts-gradle-no-test")
apply(plugin = "ts-gradle-publish")
apply(plugin = "ts-gradle-repos")
group = "cn.tursom"
version = "1.1-SNAPSHOT"
useTursomRepositories()
tasks.withType<KotlinCompile>().configureEach {
//kotlinOptions.jvmTarget = "21"
kotlinOptions.jvmTarget = "21"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
//kotlinOptions.useIR = true
}
if (!isTestRunning) {
tasks.withType<Test> {
enabled = false
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
//autoConfigPublish()
}
dependencies {

3
local.example.yml Normal file
View File

@ -0,0 +1,3 @@
tursom:
artifactoryUser: XXXX
artifactoryPassword: XXXX

View File

@ -39,6 +39,8 @@ include("ts-database:ts-redis")
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("kotlin-version", "1.9.20-RC2")
val kotlinCoroutineVersion = "1.7.3"
version("kotlin-coroutines", kotlinCoroutineVersion)
library(

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
api(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core:ts-log"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutineVersion)

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
compileOnly(group = "io.netty", name = "netty-all", version = nettyVersion)

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
api(project(":ts-core:ts-delegation"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
compileOnly(group = "com.google.code.gson", name = "gson", version = "2.8.9")

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-delegation"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))
api(group = "com.sun.mail", name = "javax.mail", version = "1.6.2")

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
api(project(":ts-core"))

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,9 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
id("ts-gradle")
kotlin("plugin.allopen") version "1.5.21"
kotlin("plugin.allopen")
}
dependencies {

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
api(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
// 解析XML https://mvnrepository.com/artifact/org.dom4j/dom4j

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
// 解析YAML

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
implementation(project(":ts-core"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":"))
implementation(project(":ts-core"))

View File

@ -1,17 +1,17 @@
//import java.text.SimpleDateFormat
//imextracted.text.SimpleDateFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
plugins {
kotlin("jvm") version "1.9.10"
kotlin("jvm") version "1.9.10" apply false
`java-gradle-plugin`
`maven-publish`
}
try {
val properties = Properties()
properties.load(file("local.properties").inputStream())
properties.forEach { (k, v) ->
ext.set(k.toString(), v)
project.ext.set(k.toString(), v)
try {
setProperty(k.toString(), v)
} catch (_: Exception) {
@ -20,104 +20,117 @@ try {
} catch (_: Exception) {
}
group = "cn.tursom"
//version = SimpleDateFormat("yy.MM.dd-HH.mm").format(Date())
version = "1.1-SNAPSHOT"
allprojects {
group = "cn.tursom"
version = "1.1-SNAPSHOT"
repositories {
maven {
url = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public/")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "java-gradle-plugin")
repositories {
maven {
url = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public/")
}
}
}
dependencies {
implementation(group = "org.yaml", name = "snakeyaml", version = "2.0")
implementation(fileTree(mapOf("dir" to "libs", "include" to arrayOf("*.jar"))))
}
extensions.configure(PublishingExtension::class) {
repositories {
publishToTursom(this, this@allprojects)
publishToGithub(this, this@allprojects)
registerPublishRepos(this, this@allprojects)
}
publications {
create<MavenPublication>("plugin") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
gradlePlugin {
plugins {
create("ts-gradle") {
// 在 app 模块需要通过 id 引用这个插件
id = "ts-gradle"
// 实现这个插件的类的路径
implementationClass = "cn.tursom.gradle.TursomGradlePlugin"
from(components["java"])
try {
artifact(tasks["kotlinSourcesJar"])
} catch (e: Exception) {
}
}
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "17"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
//kotlinOptions.useIR = true
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
publishing {
repositories {
fun publishToTursom(repositoryHandler: RepositoryHandler, project: Project) {
try {
repositoryHandler.maven {
name = "tursom"
val releasesRepoUrl = project.uri("https://jmp.mvn.tursom.cn:20080/repository/maven-releases/")
val snapshotRepoUrl = project.uri("https://jmp.mvn.tursom.cn:20080/repository/maven-snapshots/")
url = if (project.project.version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else releasesRepoUrl
println(url)
credentials {
val artifactoryUser: String = project.rootProject.ext["tursom.artifactoryUser"] as String
val artifactoryPassword: String = project.rootProject.ext["tursom.artifactoryPassword"] as String
username = artifactoryUser
password = artifactoryPassword
}
}
} catch (e: Exception) {
println("cannot push to repository tursom: ${e.javaClass}: ${e.message}")
}
}
fun publishToGithub(repositoryHandler: RepositoryHandler, project: Project) {
try {
repositoryHandler.maven {
name = "GitHubPackages"
val githubUser: String = project.rootProject.ext["github.artifactoryUser"] as String
val githubToken: String = project.rootProject.ext["github.artifactoryPassword"] as String
url = project.uri("https://maven.pkg.github.com/$githubUser/TursomServer")
credentials {
username = githubUser
password = githubToken
}
}
} catch (e: Exception) {
println("cannot push to repository github")
}
}
fun registerPublishRepos(repositoryHandler: RepositoryHandler, project: Project) {
val repositoriesRegex = "repositories\\.[a-zA-z]*".toRegex()
project.rootProject.properties.keys.asSequence().filter {
it matches repositoriesRegex
}.forEach {
val repositoryName = project.rootProject.ext.properties["$it.name"]?.toString() ?: it.substringAfterLast('.')
try {
maven {
name = "tursom"
val releasesRepoUrl = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-releases/")
val snapshotRepoUrl = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-snapshots/")
url = if (project.version.toString().endsWith("SNAPSHOT")) snapshotRepoUrl else releasesRepoUrl
val artifactoryUser = project.rootProject.ext.properties["$it.artifactoryUser"].toString()
val artifactoryPassword = project.rootProject.ext.properties["$it.artifactoryPassword"].toString()
repositoryHandler.maven {
name = repositoryName
val releasesRepoUrl = project.rootProject.ext.properties["$it.release"]?.let { project.uri(it.toString()) }
val snapshotRepoUrl = project.rootProject.ext.properties["$it.snapshot"]?.let { project.uri(it.toString()) }
val repoUrl = project.rootProject.ext.properties["$it.url"]?.let { project.uri(it.toString()) }
url = if (project.project.version.toString().endsWith("SNAPSHOT")
&& snapshotRepoUrl != null
) {
snapshotRepoUrl
} else releasesRepoUrl ?: repoUrl!!
credentials {
val artifactoryUser: String = rootProject.ext["tursom.artifactoryUser"] as String
val artifactoryPassword: String = rootProject.ext["tursom.artifactoryPassword"] as String
username = artifactoryUser
password = artifactoryPassword
}
}
} catch (e: Exception) {
println("cannot push to repository tursom: ${e.javaClass}: ${e.message}")
}
try {
maven {
name = "GitHubPackages"
val githubUser: String = rootProject.ext["github.artifactoryUser"] as String
val githubToken: String = rootProject.ext["github.artifactoryPassword"] as String
url = uri("https://maven.pkg.github.com/$githubUser/TursomServer")
credentials {
username = githubUser
password = githubToken
}
}
} catch (e: Exception) {
println("cannot push to repository github")
}
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) {
println("cannot push to repository $repositoryName")
}
println("cannot push to repository $repositoryName")
}
}
publications {
create<MavenPublication>("plugin") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
try {
artifact(tasks["kotlinSourcesJar"])
} catch (e: Exception) {
}
}
}
}
}

View File

@ -0,0 +1,2 @@
tursom.artifactoryUser: XXXX
tursom.artifactoryPassword: XXXX

View File

@ -1,3 +1,9 @@
include("ts-gradle-env")
include("ts-gradle-no-test")
include("ts-gradle-install")
include("ts-gradle-publish")
include("ts-gradle-repos")
pluginManagement {
repositories {
maven {

View File

@ -1,7 +0,0 @@
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
internal val Project.ext: ExtraPropertiesExtension
get() = (this as ExtensionAware).extensions
.getByName("ext") as ExtraPropertiesExtension

View File

@ -1,68 +0,0 @@
import org.gradle.api.DomainObjectCollection
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import java.util.concurrent.TimeUnit
fun Project.excludeTest() {
if (gradle.startParameter.taskNames.firstOrNull { taskName ->
taskName.contains("test", true)
} == null) {
tasks.run {
named("test") { it.enabled = false }
named("testClasses") { it.enabled = false }
named("compileTestJava") { it.enabled = false }
try {
named("compileTestKotlin") { it.enabled = false }
} catch (_: Exception) {
}
named("processTestResources") { it.enabled = false }
}
}
}
fun DomainObjectCollection<Configuration>.noExpire() {
all {
it.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
it.resolutionStrategy.cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
}
}
fun Project.useTursomRepositories(
useAliyunMirror: Boolean = false,
mavenCentral: Boolean = false,
tursom: Boolean = true
) {
repositories.run {
if (useAliyunMirror) {
maven {
it.url = uri("https://maven.aliyun.com/repository/public")
}
}
if (mavenCentral) {
mavenCentral()
}
if (tursom) {
maven {
it.url = uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public")
}
}
}
try {
configurations.noExpire()
} catch (_: Exception) {
}
}
fun <T> NamedDomainObjectCollection<T>.contains(name: String) = try {
findByName(name)
} catch (e: Exception) {
null
} != null
operator fun Project.get(key: String) = ext[key]?.toString()
val Project.isTestRunning
get() = gradle.startParameter.taskNames.firstOrNull { taskName ->
taskName.endsWith(":test")
} != null

View File

@ -0,0 +1,12 @@
dependencies {
implementation(group = "org.yaml", name = "snakeyaml", version = "2.0")
}
gradlePlugin {
plugins {
create("ts-gradle-env") {
id = "ts-gradle-env"
implementationClass = "cn.tursom.gradle.EnvPlugin"
}
}
}

View File

@ -1,17 +1,14 @@
package cn.tursom.gradle
import autoConfigPublish
import contains
import excludeTest
import ext
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.yaml.snakeyaml.Yaml
import java.io.FileNotFoundException
import java.util.*
class TursomGradlePlugin : Plugin<Project> {
class EnvPlugin : Plugin<Project> {
companion object {
val yaml = Yaml()
var project: Project? = null
@ -33,22 +30,9 @@ class TursomGradlePlugin : Plugin<Project> {
loadYaml(target, propertiesFile)
}
}
//println(target.ext.properties)
target.excludeTest()
if (!target.tasks.contains("install")) run install@{
val publishToMavenLocal = target.tasks.findByName("publishToMavenLocal") ?: return@install
target.tasks.register("install", DefaultTask::class.java) {
it.finalizedBy(publishToMavenLocal)
}
}
target.autoConfigPublish()
}
}
fun loadProperties(target: Project, propertiesFile: String) = try {
val properties = Properties()
properties.load(target.file(propertiesFile).inputStream())
@ -60,7 +44,7 @@ fun loadProperties(target: Project, propertiesFile: String) = try {
fun loadYaml(target: Project, propertiesFile: String) {
try {
TursomGradlePlugin.yaml.load<Map<String, Any>>(target.file(propertiesFile).inputStream()).forEach { (k, v) ->
EnvPlugin.yaml.load<Map<String, Any>>(target.file(propertiesFile).inputStream()).forEach { (k, v) ->
put(target, k, v)
}
} catch (e: Exception) {
@ -94,3 +78,7 @@ fun setProperty(target: Project, key: String, value: Any) {
} catch (e: Exception) {
}
}
val Project.ext: ExtraPropertiesExtension
get() = (this as ExtensionAware).extensions
.getByName("ext") as ExtraPropertiesExtension

View File

@ -0,0 +1,8 @@
gradlePlugin {
plugins {
create("ts-gradle-install") {
id = "ts-gradle-install"
implementationClass = "cn.tursom.gradle.InstallPlugin"
}
}
}

View File

@ -0,0 +1,23 @@
package cn.tursom.gradle
import org.gradle.api.DefaultTask
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.Plugin
import org.gradle.api.Project
class InstallPlugin : Plugin<Project> {
override fun apply(target: Project) {
if (!target.tasks.contains("install")) run install@{
val publishToMavenLocal = target.tasks.findByName("publishToMavenLocal") ?: return@install
target.tasks.register("install", DefaultTask::class.java) {
it.finalizedBy(publishToMavenLocal)
}
}
}
}
fun <T> NamedDomainObjectCollection<T>.contains(name: String) = try {
findByName(name)
} catch (e: Exception) {
null
} != null

View File

@ -0,0 +1,8 @@
gradlePlugin {
plugins {
create("ts-gradle-no-test") {
id = "ts-gradle-no-test"
implementationClass = "cn.tursom.gradle.NoTestPlugin"
}
}
}

View File

@ -0,0 +1,31 @@
package cn.tursom.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
class NoTestPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.excludeTest()
}
}
fun Project.excludeTest() {
if (gradle.startParameter.taskNames.firstOrNull { taskName ->
taskName.contains("test", true)
} == null) {
try {
tasks.run {
named("test") { it.enabled = false }
named("testClasses") { it.enabled = false }
named("compileTestJava") { it.enabled = false }
try {
named("compileTestKotlin") { it.enabled = false }
} catch (_: Exception) {
}
named("processTestResources") { it.enabled = false }
}
} catch (e: Exception) {
println("W: exclude tests failed with ${e.javaClass.name}: ${e.message}")
}
}
}

View File

@ -0,0 +1,12 @@
dependencies {
implementation(project(":ts-gradle-env"))
}
gradlePlugin {
plugins {
create("ts-gradle-publish") {
id = "ts-gradle-publish"
implementationClass = "cn.tursom.gradle.PublishPlugin"
}
}
}

View File

@ -1,10 +1,21 @@
package cn.tursom.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.PasswordCredentials
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.publish.PublicationContainer
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
class PublishPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.autoConfigPublish()
}
}
fun Project.autoConfigPublish() {
try {
extensions.configure(PublishingExtension::class.java, ::publish)
@ -173,4 +184,4 @@ private fun Project.getVersionWithProperties(): String {
}
return version
}
}

View File

@ -0,0 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
gradlePlugin {
plugins {
create("ts-gradle-repos") {
id = "ts-gradle-repos"
implementationClass = "cn.tursom.gradle.ReposPlugin"
}
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}

View File

@ -6,7 +6,7 @@ import org.gradle.api.Action
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
private const val defaultVersion = "1.0-SNAPSHOT"
private const val defaultVersion = "1.1-SNAPSHOT"
private fun DependencyHandler.add(
configurationName: String,

View File

@ -0,0 +1,54 @@
package cn.tursom.gradle
import org.gradle.api.DomainObjectCollection
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.dsl.RepositoryHandler
import java.util.concurrent.TimeUnit
class ReposPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.useTursomRepositories()
}
}
fun Project.useTursomRepositories(
useAliyunMirror: Boolean = false,
mavenCentral: Boolean = false,
tursom: Boolean = true
) {
repositories.useTursomRepositories(useAliyunMirror, mavenCentral, tursom)
try {
configurations.noExpire()
} catch (_: Exception) {
}
}
context (Project)
fun RepositoryHandler.useTursomRepositories(
useAliyunMirror: Boolean,
mavenCentral: Boolean,
tursom: Boolean
) {
if (useAliyunMirror) {
maven {
it.url = project.uri("https://maven.aliyun.com/repository/public")
}
}
if (mavenCentral) {
mavenCentral()
}
if (tursom) {
maven {
it.url = project.uri("https://jmp.mvn.tursom.cn:20080/repository/maven-public")
}
}
}
fun DomainObjectCollection<Configuration>.noExpire() {
all {
it.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
it.resolutionStrategy.cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
}
}

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-coroutine"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":ts-core"))
implementation(project(":ts-core:ts-buffer"))

View File

@ -1,7 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
implementation(project(":"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
val brotliVersion = "1.7.1"
val operatingSystem: OperatingSystem =
org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem()

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
api(project(":ts-core:ts-buffer"))

View File

@ -1,8 +1,3 @@
plugins {
kotlin("jvm")
id("ts-gradle")
}
dependencies {
api(project(":ts-core"))
api(project(":ts-core:ts-buffer"))