如何更改Artifactory运行时范围以编译范围? [英] How to change artifactory runtime scope to compile scope?
问题描述
我正在研究一个使用gradle和jfrog插件发布到artifactory的项目。重要的代码片段如下:
插件{
idjava
ididea
idgroovy
idpmd
idfindbugs
idmaven-publish
idcom.jfrog.artifactoryversion3.1.1
依赖关系{
编译'com.google.guava:guava:18.0'
compile'com.mashape.unirest:unirest-java:1.4。 5'
编译'log4j:log4j:1.2.14'
}
artifactory {
contextUrl =https:// SOME_SERVER / artifactory
发布{
repository {
repoKey ='libs-snapshot-local'
username = artifactory_username
password = artifactory_password
maven = true
}
默认{
出版物('mavenJava')
}
}
}
出版{
出版物{
mavenJava( MavenPublication){从components.java
}
$ b $ p
$ b 当我执行gradle artifactory时,一切似乎都正常。文物被发布并且生成一个pom文件。
遗憾的是,pom文件中的依赖项都有一个运行时作用域:
<?xml version =1.0encoding =UTF-8?>
< project xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdxmlns = 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>
<依赖关系>
< dependency>
< groupId> com.google.guava< / groupId>
< artifactId>番石榴< / artifactId>
< version> 18.0< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> com.mashape.unirest< / groupId>
< artifactId> unirest-java< / artifactId>
< version> 1.4.5< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.14< / version>
< scope>运行时< / scope>
< /依赖关系>
< /依赖关系>
< / project>
代替这个运行期范围,它们应该有一个编译范围。我究竟做错了什么?
解决方案从来没有在practive上试过,但您可以尝试使用 publication.pom.withXml
code>配置块来引入生成的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 。
I am working on a project that uses gradle and the jfrog plugin to publish to artifactory. The important code fragments are these:
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
}
}
}
When I do a gradle artifactoryPublish everything seems to work fine. The artefacts are published and a pom file is generated as well.
Regretfully the dependencies in the pom file all have a runtime scope:
<?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>
Instead of this runtime scope they should have a compile scope. What am I doing wrong?
解决方案 Never tried this on practive, but you can try to use publication.pom.withXml
configuration block to introduce changes in generated 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'
}
}
}
}
}
Also, this is a known limitation of new publishing plugin and I found the solution in this thread.
这篇关于如何更改Artifactory运行时范围以编译范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!