java - Ant 和Gradle混合体将jar和pom发布到Artifactory

标签 java maven gradle groovy ant

我正在尝试使用Ant进行构建,并尝试使用Gradle将jar和pom发布到Artifactory,但是有些运气不好。希望还没有用完,因为我需要/希望做到这一点。

task createPom() {
    pom {
        project {
            groupId "${groupId}"
            artifactId 'pluginmanager'
            version "${version}"
        }
    }.writeTo('pom.xml')
}

def pomfile = file('pom.xml')

task publishPom(type: Upload) {
    dependsOn 'createPom'
    artifacts {
        archives pomfile
    }
    repositories {
       "${artifactory_url}"
    }
}

artifactory() {
    publish {
        repository {
            repoKey = "${repoKey}"
        }
    }
}

artifactoryPublish {
    dependsOn 'publishPom'
}

现在,显然我很想知道如何writeTo('pom.xml')然后创建(def)pomfile,但是那让我迷失了如何进行这项工作。在writeTo上,当我将存档定义为“pomfile.xml”时,无法传递pomfile变量和publishPom构件块,我得到“无法转换提供的PublishArtifact类型的对象表示法:pom.xml”错误,它告诉我使用“文件实例”。但是,当我传入pomfile变量时,出现一个新错误,“未为属性'artifacts'指定值”。

我的Gradle任务createPom()有效,但是我无法运行publishPom()。到现在,这可能已经很明显了。

最佳答案

Maven Publishing plugin已经负责生成POM并提供发布任务。您的方法尝试手动创建该代码。

您可以执行以下操作:

apply plugin: 'maven-publish'

ext {
    jarFileCreatedByAnt = file('my.jar')
    artifactoryUrl = 'http://localhost:4001/artifactory'
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId 'org.gradle.sample'
            artifactId 'pluginmanager'
            version '1.1'
            artifact jarFileCreatedByAnt
        }
    }
    repositories {
        maven {
            url artifactoryUrl
        }
    }
}

然后运行任务publishMavenJavaPublicationToMavenRepository。当然,JAR文件需要预先存在。

关于java - Ant 和Gradle混合体将jar和pom发布到Artifactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48572865/

相关文章:

java - 服务器/客户端通信不工作java

java - org.openqa.selenium.SessionNotCreatedException : Unable to create session error using GeckoDriver and Firefox through Selenium and Java

java - Eclipse Maven 导出丢失

Gradle zip 任务给出 NO-SOURCE

Java 插件未附加到 Eclipse 中的调试 session

java - JViewport 是不是定位了它的 View ?

maven - 如何使用 Maven Reactor 构建模块及其子模块?

java - Spring + TestNG 不事务回滚

java - Gradle 'error: package com.google.common.collect does not exist'

gradle - 使用Gradle将org.apache.kafka添加到依赖项