java - 如何发布没有源的 JAR?

标签 java spring-boot kotlin gradle

我有一个多模块 Kotlin Gradle 项目:

data-cassandra
-- cassandra-autoconfigure
-- cassandra-starter
cassandra-autoconfigure有源代码,其他两个没有。 cassandra-starter的人生目标是引进cassandra-autoconfigureapi(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/

相关文章:

java - 从 tomcat6 到 jboss5 的远程 ejb 调用导致 : Could not dereference object exception

java - 运行 Spring Boot 应用程序时出现兼容版本问题,但在 pom 中只有版本

java - header 位置不重定向

kotlin - 如何检查 Kotlin 中的泛型类型?

intellij-idea - 如何以编程方式为 Intellij Idea 创建自定义 Kotlin Inspection

java - 初始化的ArrayList不显示

java - 从文件中读取字符串数据

java - JTextField 剪裁

java - 指定 AWS Cloudwatch 日志客户端的凭证

android - 使用导航组件移动到新 fragment 时出错