简体   繁体   English

Jenkins Artifactory插件不生成POM文件

[英]Jenkins Artifactory plugin not generating POM file

I am successfully building my gradle project in Jenkins and deploying the jars to artifactory. 我正在詹金斯成功建立我的gradle项目并将罐子部署到神器中。 However when I try to reuse them in another project the additional dependencies are not recognized/downloaded. 但是,当我尝试在另一个项目中重用它们时,无法识别/下载其他依赖项。 I presume this has to do with the missing pom file in artifactory. 我认为这与神器中缺少的pom文件有关。

In artifactory the JAR files are correctly uploaded but there is no POM file next to it. 在神器中,JAR文件已正确上载,但旁边没有POM文件。

Am I correct in understanding that I need this POM file for gradle to resolve the jar's dependecies when trying to download it again? 我是否理解我需要这个POM文件以便gradle在尝试再次下载时解决jar的依赖? And why is the POM file not generated? 为什么没有生成POM文件?

The job settings are: 作业设置为:

Gradle-Artifactory Integration Gradle-Artifactory整合

Project uses the Artifactory Gradle Plugin = false
Capture and publish build info = true
Publish artifacts to Artifactory = true
    Publish Maven descriptors = true
Use Maven compatible patterns = true
    patterns are default: [organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]

Build: 建立:

use gradle wrapper = true
tasks = build

A Maven repository indeed provides artefacts (normally jar files) and pom files ( .pom extension) listing the required dependencies and their scope (so that they can transitively resolved to recreate the whole required dependency graph per each artefact). Maven存储库确实提供了人工制品(通常是jar文件)和pom文件( .pom扩展名),列出了所需的依赖关系及其范围(以便它们可以传递解析,以便为每个.pom重新创建整个所需的依赖关系图)。 So indeed you would need the jar and the .pom file. 所以你确实需要jar和.pom文件。

I had exactly the same issue but for a maven build. 我有完全相同的问题,但对于maven构建。 In my case the Jenkins build was executing the mvn clean package command, which effectively creates the desired jar file. 在我的例子中,Jenkins构建正在执行mvn clean package命令,该命令有效地创建了所需的jar文件。 Then the Artifactory Jenkins Plugin was correctly pushing the jar to Artifactory, perfectly available with the desired Maven coordinates (GAV, groupId, artifactId, version). 然后Artifactory Jenkins插件正确地将jar推送到Artifactory,完全可用所需的Maven坐标(GAV,groupId,artifactId,version)。 However, the .pom file was missing. 但是,.pom文件丢失了。
In my case, solution was to change the invoked Maven phase, from package to install . 在我的例子中,解决方案是更改调用的Maven阶段,从packageinstall The install phase indeed creates also the desired .pom file and additionally installs the artefact on the local repository (the Maven cache). install阶段确实还创建了所需的.pom文件,并在本地存储库(Maven缓存)上另外安装了artefact。

So, simply switching to mvn clean install , the Artifactory Jenkins Plugin was correctly uploading .jar and .pom file. 因此,只需切换到mvn clean install ,Artifactory Jenkins插件就可以正确上传.jar.pom文件。

In your case, for a gradle build the issue could potentially be the same. 在您的情况下,对于gradle构建,问题可能是相同的。 You are probably creating the expected jar file and the Artifactory Jenkins Plugin is correctly picking it up and pushing it to Artifactory, but no .pom file is generated and as such not uploaded. 您可能正在创建预期的jar文件,Artifactory Jenkins插件正确地将其拾取并将其推送到Artifactory,但是没有生成.pom文件,因此没有上传。 So, if you are invoking gradle assemble or gradle build you are correctly generating the jar, but not the .pom file. 因此,如果您正在调用gradle assemblegradle build ,则gradle build您正在生成jar,而不是.pom文件。 You should probably also execute on the Jenkins build a gradle install command using the maven plugin as explained in this other SO answer and by the plugin documentation , from which we can also read: 你应该还执行对詹金斯建立gradle install使用Maven插件作为解释的命令其他的SO回答,并通过插件文档 ,从中我们也可以读到:

31.6.3. 31.6.3。 Installing to the local repository 安装到本地存储库
The Maven plugin adds an install task to your project. Maven插件为您的项目添加了一个安装任务。 This task depends on all the archives task of the archives configuration. 此任务取决于归档配置的所有归档任务。 It installs those archives to your local Maven repository. 它将这些存档安装到您的本地Maven存储库。

31.6.4. 31.6.4。 Maven POM generation Maven POM一代
When deploying an artifact to a Maven repository, Gradle automatically generates a POM for it. 将工件部署到Maven存储库时,Gradle会自动为其生成POM。

Beware though that " While the maven plugin does provide the install task, it only adds the task in the presence of the java plugin ". 请注意虽然maven插件确实提供了安装任务,但它只会在存在java插件的情况下添加任务 ”。 Alternatively, to create the .pom file, you could also consider the maven-publish plugin and its publishToMavenLocal task. 或者,要创建.pom文件,您还可以考虑maven-publish插件及其publishToMavenLocal任务。

So, to summarize: to properly create .jar and .pom file, you need to install the artefact on the local cache (in your case: the local cache of the Jenkins server, an harmless action), because as part of this process the required files are created as output of the build. 因此,总结一下:要正确创建.jar.pom文件,您需要在本地缓存上安装artefact(在您的情况下:Jenkins服务器的本地缓存,一个无害的操作),因为作为此过程的一部分,创建所需文件作为构建的输出。 The Artifactory Jenkins Plugin will then pick them up and properly upload them. Artifactory Jenkins插件然后将它们拾起并正确上传它们。

Update 更新
Alternatively and as described in the comments below (and in another SO question ), you could also avoid the install step and rather add a createPom task to your gradle build, in order to create the POM file as following: 或者,如下面的注释(以及另一个SO问题 )中所述,您还可以避免install步骤,而是将createPom任务添加到gradle构建中,以便按如下方式创建POM文件:

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

What helped me was adding the following configuration: 帮助我的是添加以下配置:

Include Patterns: *.pom *.jar

There also should be enabled maven plugin in build.gradle: 还应该在build.gradle中启用maven插件:

apply plugin: 'maven-publish'

After that generated pom and artifacts were successfully uploaded by Jenkins job to Artifactory. 之后,Jenkins的工作成功地将生成的pom和工件上传到Artifactory。 Make sure that Publish Maven descriptors flag is set to true. 确保将Publish Maven descriptors标志设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM