英文:
Kotlin Gradle build with Spring Boot not publishing jars to Artifactory - only build info
问题
我正在尝试将一个 Spring Boot 的 JAR 发布到 Artifactory,但无法使其工作。以下是我的 build.gradle.kts
文件内容:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
group = "com.blah"
version = "0.0.2"
java.sourceCompatibility = JavaVersion.VERSION_1_8
plugins {
id("maven-publish")
id("org.springframework.boot") version "2.3.1.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
id("com.google.cloud.tools.jib") version "2.5.0"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
id("com.jfrog.artifactory") version "4.13.0"
}
tasks.getByName<Jar>("jar") {
enabled = true
}
tasks.getByName<Jar>("bootJar") {
classifier = "application"
}
repositories {
mavenCentral()
maven {
setUrl("https://artifactory:443/artifactory/txo-maven-virtual")
credentials {
username = System.getenv("ARTIFACTORY_USR")
password = System.getenv("ARTIFACTORY_PSW")
}
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
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")
}
}
artifactory {
setContextUrl("https://artifactory/artifactory")
publish(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper> {
setProperty("repoKey", "txo-")
setProperty("username", System.getenv("ARTIFACTORY_USR"))
setProperty("password", System.getenv("ARTIFACTORY_PSW"))
setProperty("maven", true)
})
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod("publications", "mavenJava")
})
})
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
这将构建并推送构建信息到 artifactory/api/build
,但不会推送任何 JAR 文件。
如果我取消注释掉的部分,会得到以下错误:
> * 出现了什么问题:找不到名称为 'mavenJava' 的发布。
如何使这个配置能够发布我的 JAR 文件呢?
英文:
I'm trying to publish a Spring Boot jar to Artifactory and cannot get it to work. Here's my build.gradle.kts
:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
group = "com.blah"
version = "0.0.2"
java.sourceCompatibility = JavaVersion.VERSION_1_8
plugins {
id("maven-publish")
id("org.springframework.boot") version "2.3.1.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
id("com.google.cloud.tools.jib") version "2.5.0"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
id("com.jfrog.artifactory") version "4.13.0"
}
tasks.getByName<Jar>("jar") {
enabled = true
}
tasks.getByName<Jar>("bootJar") {
classifier = "application"
}
repositories {
mavenCentral()
maven {
setUrl("https://artifactory:443/artifactory/txo-maven-virtual")
credentials {
username = System.getenv("ARTIFACTORY_USR")
password = System.getenv("ARTIFACTORY_PSW")
}
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
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")
}
}
//publishing {
// (publications) {
// "mavenJava" (MavenPublication::class) {
// from(components["java"])
// }
// }
//}
artifactory {
setContextUrl("https://artifactory/artifactory")
publish(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
repository(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper> {
setProperty("repoKey", "txo-")
setProperty("username", System.getenv("ARTIFACTORY_USR"))
setProperty("password", System.getenv("ARTIFACTORY_PSW"))
setProperty("maven", true)
})
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
invokeMethod("publications", "mavenJava")
})
})
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
This builds and pushes the build info to artifactory/api/build
but does not push any jars.
If I uncomment the commented-out stuff, I get:
> * What went wrong: Publication with name 'mavenJava' not found.
How can I get this thing to publish my jar files?
答案1
得分: 1
尝试一下:
发布 {
发布物 {
注册("mavenJava", MavenPublication::class) {
来自(components["java"])
}
}
}
<details>
<summary>英文:</summary>
Try this:
publishing {
publications {
register("mavenJava", MavenPublication::class) {
from(components["java"])
}
}
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论