When I use the gradle plug-in maven pbulish
to upload jars to the Maven repository, how can I exclude some dependencies in the gradle project?
My gradle. Build file is as follows:
dependencies {
compile project(":frame:f_frame");
compile project(":p_AppComm");
compile project(":p_Systemaudit");
}
publishing {
repositories {
maven {
url = 'http://XXX/repository/infra_test_snapshot/'
credentials {
username = 'admin'
password = 'admin'
}
}
}
publications {
maven(MavenPublication) {
groupId "AAAAA"
artifactId "BBBBB"
version "CCCCC"
from components.java
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
if (it.name != null && !"unspecified".equals(it.name) && !"f_frame".equals(it.name) && !"p_AppComm".equals(it.name)) {
println it.toString()
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'implementation')
}
}
}
artifact sourceJar {
classifier "sources"
}
}
}
}
How can I modify the contents of the pom.withxml
function to remove the f_frame
and p_Appcomm
in the POM file dependency in the Maven repository.
CodePudding user response:
dependencyNode.appendNode('scope', 'implementation')
. maven does not have any 'implementation' scope, valid values are - compile, provided, runtime, testprint all the names / types of the dependencies in the dependencies loop - exclude all 'project' type dependencies - like your if condition
CodePudding user response:
When publishing jar packages using maven-publish
plug-in, dependencies have been added to the automatically generated POM file according to dependencies{}
. I shouldn't add the same dependencies again. The correct way is to cycle the asNode()
and remove the parts I don't need.
The modified code is as follows:
pom.withXml {
Node pom = asNode()
NodeList pomNodes = pom.value()
Node dependencies = pomNodes.get(4)
NodeList pomDependencies = dependencies.value()
Iterator iterator = pomDependencies.iterator();
while (iterator.hasNext()) {
Node dependeny = iterator.next()
NodeList str = dependeny.get("artifactId")
String dependName = str.get(0).value().get(0)
if ("f_frame".equals(dependName) || "p_AppComm".equals(dependName)) {
iterator.remove()
}
}
}