Kotlin Gradle构建与Spring Boot一起使用,未将JAR发布到Artifactory – 仅构建信息

huangapple go评论76阅读模式
英文:

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 = &quot;com.blah&quot;
version = &quot;0.0.2&quot;
java.sourceCompatibility = JavaVersion.VERSION_1_8

plugins {
    id(&quot;maven-publish&quot;)
    id(&quot;org.springframework.boot&quot;) version &quot;2.3.1.RELEASE&quot;
    id(&quot;io.spring.dependency-management&quot;) version &quot;1.0.9.RELEASE&quot;
    id(&quot;com.google.cloud.tools.jib&quot;) version &quot;2.5.0&quot;
    kotlin(&quot;jvm&quot;) version &quot;1.3.72&quot;
    kotlin(&quot;plugin.spring&quot;) version &quot;1.3.72&quot;
    id(&quot;com.jfrog.artifactory&quot;) version &quot;4.13.0&quot;
}

tasks.getByName&lt;Jar&gt;(&quot;jar&quot;) {
    enabled = true
}


tasks.getByName&lt;Jar&gt;(&quot;bootJar&quot;) {
    classifier = &quot;application&quot;
}

repositories {
    mavenCentral()
    maven {
        setUrl(&quot;https://artifactory:443/artifactory/txo-maven-virtual&quot;) 
        credentials {               
            username = System.getenv(&quot;ARTIFACTORY_USR&quot;) 
            password = System.getenv(&quot;ARTIFACTORY_PSW&quot;)
        }
    }
}

dependencies {
    implementation(&quot;org.springframework.boot:spring-boot-starter&quot;)
    implementation(&quot;org.springframework.boot:spring-boot-starter-web&quot;)
    implementation(&quot;com.fasterxml.jackson.module:jackson-module-kotlin&quot;)
    implementation(&quot;org.jetbrains.kotlin:kotlin-reflect&quot;)
    implementation(&quot;org.jetbrains.kotlin:kotlin-stdlib-jdk8&quot;)

    testImplementation(&quot;org.springframework.boot:spring-boot-starter-test&quot;) {
        exclude(group = &quot;org.junit.vintage&quot;, module = &quot;junit-vintage-engine&quot;)
    }
}

//publishing {
//    (publications) {
//        &quot;mavenJava&quot; (MavenPublication::class) {
//            from(components[&quot;java&quot;])
//        }
//    }
//}

artifactory {
    setContextUrl(&quot;https://artifactory/artifactory&quot;)
    publish(delegateClosureOf&lt;org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig&gt; {
        repository(delegateClosureOf&lt;org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper&gt; {
            setProperty(&quot;repoKey&quot;, &quot;txo-&quot;)
            setProperty(&quot;username&quot;, System.getenv(&quot;ARTIFACTORY_USR&quot;))
            setProperty(&quot;password&quot;, System.getenv(&quot;ARTIFACTORY_PSW&quot;))
            setProperty(&quot;maven&quot;, true)
        })
        defaults(delegateClosureOf&lt;groovy.lang.GroovyObject&gt; {
            invokeMethod(&quot;publications&quot;, &quot;mavenJava&quot;)
        })
    })
}

tasks.withType&lt;Test&gt; {
    useJUnitPlatform()
}

tasks.withType&lt;KotlinCompile&gt; {
    kotlinOptions {
        freeCompilerArgs = listOf(&quot;-Xjsr305=strict&quot;)
        jvmTarget = &quot;1.8&quot;
    }
}

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>



huangapple
  • 本文由 发表于 2020年10月14日 00:05:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/64338981.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定