如何发布一个没有源代码的jar?

hgqdbh6s  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(390)

我有一个多模块kotlin gradle项目:

data-cassandra
-- cassandra-autoconfigure
-- cassandra-starter
``` `cassandra-autoconfigure` 有源代码,其他两个没有。 `cassandra-starter` 他的人生目标是 `cassandra-autoconfigure` 作为 `api(project(":cassandra-autoconfigure"))` ; 这是 Spring 的标准惯例。 `cassandra-starter` 有一些测试代码,但在 `src/main/kotlin` .
问题是,当我试图发布这些项目时,它失败了。

Artifact cassandra-starter-1.0.0-SNAPSHOT.jar wasn't produced by this build.

这是真的,我看得出来 `> Task :cassandra-starter:jar SKIPPED` . 我怎么强迫grad尔只用 `META-INF` 在里面?
数据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 {
doFirst {
println("Publishing ${publication.groupId}:${publication.artifactId}:${publication.version} to ${repository.url}")
}
}

cassandra自动配置/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初学者/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
}

odopli94

odopli941#

回答我自己的问题,来自spring boot文档:
默认情况下,配置bootjar或bootwar任务时,jar或war任务被禁用。通过启用jar或war任务,可以将项目配置为同时构建可执行存档和普通存档:
cassandra初学者/build.gradle.kts

tasks.jar {
    enabled = true
}

解决了这个问题。

相关问题