-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
188 lines (161 loc) · 7.45 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import org.apache.maven.settings.Settings
import org.apache.maven.settings.io.DefaultSettingsReader
import org.apache.maven.settings.io.SettingsReader
import org.gradle.api.internal.artifacts.mvnsettings.DefaultMavenFileLocations
import org.gradle.api.internal.artifacts.mvnsettings.DefaultMavenSettingsProvider
import kotlin.reflect.full.declaredMemberProperties
import org.gradle.api.internal.artifacts.mvnsettings.MavenFileLocations
import kotlin.reflect.jvm.isAccessible
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version libs.versions.kotlin
kotlin("plugin.allopen") version libs.versions.kotlin // class默认是open
kotlin("kapt") version libs.versions.kotlin
java // 编译和测试Java源代码并将其组装成JAR文件的插件
`maven-publish` // maven发布
alias(libs.plugins.orgSpringframeworkBoot) apply false // 使用spring-boot-dependencies依赖管理版本,并支持打成可执行jar
alias(libs.plugins.ioSpringDependencyManagement) // 提供类似maven依赖管理功能
}
allprojects {
group = "com.github.hutiquan"
version = "2.0-SNAPSHOT"
repositories {
maven("http://nexus.hgj.net/repository/public") { isAllowInsecureProtocol = true }
maven("https://maven.aliyun.com/nexus/content/groups/public")
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://maven.aliyun.com/nexus/content/repositories/gradle-plugin")
mavenCentral()
maven("https://plugins.gradle.org/m2/")
}
apply {
plugin("kotlin")
plugin("java")
}
}
tasks.jar{ enabled = false}
subprojects {
apply {
plugin("io.spring.dependency-management")
plugin("kotlin-kapt")
plugin("maven-publish")
plugin("kotlin-allopen")
}
allOpen {
preset("spring")
}
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
dependencies {
// testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
// testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
tasks.jar { enabled = true }
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17 // 指定编译.java文件的jdk版本
targetCompatibility = JavaVersion.VERSION_17 // 确保.class文件与targetCompatibility所指定版本或者更新版本的java虚拟机兼容
toolchain {
languageVersion.set(JavaLanguageVersion.of("17"))
vendor.set(JvmVendorSpec.ORACLE)
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict") // 添加-Xjsr305编译器标志来启用此功能strict
jvmTarget = "17" // Kotlin 编译器配置为生成 Java 8 字节码(默认为 Java 6)
}
}
val configure: (PublishingExtension).() -> Unit = {
repositories {
maven {
name = "hgjMaven"
/*fun DefaultMavenSettingsProvider.readLocalSettings(): Settings? {
val options = mapOf(SettingsReader.IS_STRICT to false)
val settingsReader = DefaultSettingsReader()
val mavenFileLocationsKP = DefaultMavenSettingsProvider::class.declaredMemberProperties.find { it.name == "mavenFileLocations" }
?: return null
mavenFileLocationsKP.isAccessible = true
val mavenFileLocations = mavenFileLocationsKP.get(this) as MavenFileLocations
val settings = settingsReader.read((mavenFileLocations.globalSettingsFile ?: return null), options)
return settings
}
val mavenFileLocations = DefaultMavenFileLocations()
val mavenSettingsProvider = DefaultMavenSettingsProvider(mavenFileLocations)
val settings = mavenSettingsProvider.readLocalSettings()*/
val nexusReleases = "nexus.releases"
val nexusSnapshot = "nexus.snapshots"
val nexusPublic = "nexus.public"
val defaultMavenFileLocations = DefaultMavenFileLocations()
val userSettingsFile = defaultMavenFileLocations.userSettingsFile ?: defaultMavenFileLocations.globalSettingsFile
var settings: Settings? = null
try {
settings = DefaultSettingsReader().read(userSettingsFile, mapOf(SettingsReader.IS_STRICT to false))
} catch (_: Exception) {
//ignore
}
val sever =
settings?.servers?.find { it.id == nexusReleases || it.id == nexusSnapshot || it.id == nexusPublic }
?: return@maven
credentials {
username = sever.username
password = sever.password
}
val isSnapshot = version.toString().endsWith("SNAPSHOT", true)
val allConfiguredRepository = settings.profiles.flatMap { it.repositories }
val repositoryUrl =
allConfiguredRepository.find { if (isSnapshot) it.id == nexusSnapshot else it.id == nexusReleases }?.url
url = repositoryUrl?.let { uri(it) } ?: return@maven
isAllowInsecureProtocol = true
}
publications {
create<MavenPublication>("hgjMaven") {
from(components["java"])
pom {
artifactId = tasks.jar.orNull?.archiveBaseName?.get()
packaging = "jar"
name.set(rootProject.name)
description.set("Springboot整合MybatisPlus、Atomikos、多数据源读写分离")
url.set("http://git.hgj.net/booking/sharding-dynamic")
inceptionYear.set("2022")
organization {
name.set("海管家")
url.set("https://www.hgj.com")
}
/*licenses {
license {
name.set("Eclipse Public License v2.0")
url.set("http://www.eclipse.org/legal/epl-v20.html")
distribution.set("inside artifact")
comments.set("Successor of EPL v1.0")
}
}*/
developers {
developer {
id.set("TiQuan Hu")
name.set("TiQuan Hu")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:http://git.hgj.net/booking/sharding-dynamic")
developerConnection.set("scm:git:ssh://[email protected]:8022/booking/sharding-dynamic.git")
url.set("http://git.hgj.net/booking/sharding-dynamic")
tag.set("HEAD")
}
}
}
}
}
}
afterEvaluate {
if (!project.ext.has("deploy.skip")) {
publishing(configure)
}
}
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}