我有一个多模块 Kotlin Gradle 项目:
data-cassandra
-- cassandra-autoconfigure
-- cassandra-starter
cassandra-autoconfigure
有源代码,其他两个没有。 cassandra-starter
的人生目标是引进cassandra-autoconfigure
如api(project(":cassandra-autoconfigure"))
;这是 standard convention in Spring Boot . cassandra-starter
有一些测试代码,但 src/main/kotlin
中没有.问题是,当我尝试发布这些项目时,它失败了。
Artifact cassandra-starter-1.0.0-SNAPSHOT.jar wasn't produced by this build.
这是真的,我可以看到 > Task :cassandra-starter:jar SKIPPED
.如何强制 Gradle 仅使用 META-INF
构建 jar在里面?数据-cassandra/build.gradle.kts :
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
kotlin("jvm") apply false
`maven-publish`
}
allprojects {
group = "mycompany.data"
version = "1.0.0-SNAPSHOT"
repositories {
mavenCentral()
}
}
subprojects {
apply(plugin = "kotlin")
apply(plugin = "maven-publish")
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xjsr305=strict"
)
jvmTarget = "11"
}
}
plugins.withType<JavaPlugin> {
extensions.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
val springBootVersion: String by project
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
exclude(group = "com.vaadin.external.google", module = "android-json")
}
}
}
val isSnapshot = project.version.toString().toLowerCase().endsWith("snapshot")
val artifactoryUrl = property("artifactoryUrl") as String
extensions.configure<PublishingExtension> {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
repositories {
maven {
url = uri(artifactoryUrl + if (isSnapshot) "/libs-snapshot-local" else "/libs-release-local")
credentials {
username = property("artifactoryUsername") as String
password = property("artifactoryPassword") as String
}
if (!artifactoryUrl.startsWith("https")) {
isAllowInsecureProtocol = true
}
}
}
}
}
}
tasks.withType<PublishToMavenRepository> {
doFirst {
println("Publishing ${publication.groupId}:${publication.artifactId}:${publication.version} to ${repository.url}")
}
}
cassandra-autoconfigure/build.gradle.kts plugins {
kotlin("jvm")
kotlin("plugin.spring")
}
val springDataVersion: String by project
dependencies {
implementation(platform("org.springframework.data:spring-data-releasetrain:$springDataVersion"))
api("org.springframework.boot:spring-boot-starter-data-cassandra-reactive")
}
cassandra-starter/build.gradle.kts plugins {
id("org.springframework.boot")
kotlin("jvm")
kotlin("plugin.spring")
}
val cassandraUnitVersion: String by project
dependencies {
api(project(":cassandra-autoconfigure"))
testImplementation("org.cassandraunit:cassandra-unit:$cassandraUnitVersion") {
exclude(group = "org.hibernate", module = "hibernate-validator")
}
}
tasks.bootJar {
enabled = false
}
最佳答案
回答我自己的问题,来自 Spring Boot docs :
By default, when the bootJar or bootWar tasks are configured, the jar or war tasks are disabled. A project can be configured to build both an executable archive and a normal archive at the same time by enabling the jar or war task:
cassandra-starter/build.gradle.kts
tasks.jar {
enabled = true
}
解决了这个问题。
关于java - 如何发布没有源的 JAR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63714701/