gpt4 book ai didi

gradle - 如何将 Artifactory 运行时范围更改为编译范围?

转载 作者:行者123 更新时间:2023-12-03 03:40:36 24 4
gpt4 key购买 nike

我正在一个使用gradle和jfrog插件发布到 Artifact 的项目。重要的代码片段如下:

plugins {
id "java"
id "idea"
id "groovy"
id "pmd"
id "findbugs"
id "maven-publish"
id "com.jfrog.artifactory" version "3.1.1"
}

dependencies {
compile 'com.google.guava:guava:18.0'
compile 'com.mashape.unirest:unirest-java:1.4.5'
compile 'log4j:log4j:1.2.14'
}

artifactory {
contextUrl = "https://SOME_SERVER/artifactory"
publish {
repository {
repoKey = 'libs-snapshot-local'
username = artifactory_username
password = artifactory_password
maven = true
}
defaults {
publications ('mavenJava')
}
}
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}

当我做gradle人工制品发布时,一切似乎工作正常。文物将被发布,并且还将生成一个pom文件。

遗憾的是,pom文件中的依赖项都具有 运行时范围:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.whatsoever</groupId>
<artifactId>some-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

而不是此运行时范围,它们应该具有编译范围。我究竟做错了什么?

最佳答案

从未在practive上尝试过此方法,但是可以尝试使用publication.pom.withXml配置块在生成的pom中引入更改:

publishing {
publications {
mavenJava(MavenPublication) {
from components.java

pom.withXml {
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
it.scope*.value = 'compile'
}
}
}
}
}

另外,这是新发布插件的已知限制,我在 this thread中找到了解决方案。

关于gradle - 如何将 Artifactory 运行时范围更改为编译范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31069666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com