-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gradle plugin: Duplicated tag: 'dependencyManagement' #198
Comments
I had the same problem. You don´t need to/cannot use the 'io.spring.dependency-management' plugin in the project where you use your bom. so no "dependencymanagement in the build gradle too! All you need is: dependencies {
//your deps } |
Had the same problem and just implemented a hack that combines the content of the two dependency management blocks.
|
Hi @piacenti , Thanks for sharing the hack. I am also facing the same issue. Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'generatePomFileForCoreJarPublication' for root project 'project-name' of type org.gradle.api.Project. Any idea what's wrong here? |
Hi @lauraliparulo , explicitly defining the dependency does add the dependency.
However I still get an extra dependencyManagement element in the end for spring-boot-dependencies.
|
Kotlin variant of the fix:
Note that this only works if |
@micheljung Thank you for your workaround fix and idea. I wrote another workaround implementation. I may help somebody. // FIXME workaround for https://github.com/jfrog/build-info/issues/198
val fixPom = tasks.register("fixPom") {
doLast {
val file = Path.of("$buildDir/publications/mavenJava/pom-default.xml")
val content = Files.readString(file)
val tag = "dependencyManagement"
val findAll = "<$tag>".toRegex().findAll(content)
if (findAll.count() == 2) {
val tagEnd = "</$tag>"
val start = findAll.toList()[1].range.first
val end = content.indexOf(tagEnd, start) +tagEnd.length
val fixedContent = content.removeRange(start, end)
Files.writeString(file, fixedContent)
} else {
println("Is https://github.com/jfrog/build-info/issues/198 fixed already?")
}
}
}
tasks.findByName("generatePomFileForMavenJavaPublication")?.finalizedBy(fixPom)
?: throw NullPointerException("Task 'generatePomFileForMavenJavaPublication' was not found in " + tasks.names)
|
@micheljung @mpeterka thank you guys for your effort. We've encountered the same issue after adding a transitive dependency constraint for a security reason. The following solution merges I didn't use the exceptions but nested if blocks, since I'm not sure about the way Gradle handles them, hence if you know it - feel free to optimize it further. import java.nio.file.Files
import java.util.regex.Pattern
import java.nio.file.Path as FilePath
/**
* Task to merge multiple <dependencyManagement> tags created in the POM file to publish.
* Caused by: https://github.com/jfrog/build-info/issues/198 (io.spring.dependency-management + dependency constraints)
*/
val fixPom = tasks.register("fixPom") {
doLast {
val pomFilePath = FilePath.of("$buildDir/publications/mavenJava/pom-default.xml")
val pomContent = Files.readString(pomFilePath)
if ("<dependencyManagement>" in pomContent) {
val (pomContentWithoutDependencyManagement, dependencyManagementTagContents) =
extractDependencyManagementTags(pomContent)
fixPomFileIfMultipleDependencyManagementTagsArePresent(
pomContent,
pomContentWithoutDependencyManagement,
dependencyManagementTagContents,
pomFilePath
)
} else
logger.warn("Didn't find any <dependencyManagement> tags, maybe this project doesn't need this fix task")
}
}
fun extractDependencyManagementTags(pomContent: String): Pair<String, List<String>> {
val pattern = Pattern.compile(
"""(<dependencyManagement>.*?<dependencies>)(.+?)(</dependencies>.*?</dependencyManagement>)""",
Pattern.DOTALL
)
var pomContentWithoutDependencyManagement = pomContent
var matcher = pattern.matcher(pomContentWithoutDependencyManagement)
val dependencyManagementTagContents = mutableListOf<String>()
while (matcher.find()) {
dependencyManagementTagContents.add(matcher.group(2))
pomContentWithoutDependencyManagement = matcher.replaceFirst("")
matcher = pattern.matcher(pomContentWithoutDependencyManagement)
}
return Pair(pomContentWithoutDependencyManagement, dependencyManagementTagContents)
}
fun fixPomFileIfMultipleDependencyManagementTagsArePresent(
pomContent: String,
pomContentWithoutDependencyManagement: String,
dependencyManagementTagContents: List<String>,
pomFilePath: FilePath?
) {
if (dependencyManagementTagContents.size > 1) {
val indexToInsertDependencyManagementTag = pomContent.indexOf("<dependencyManagement>")
val fixedPomContent = getFixedPomContent(
pomContentWithoutDependencyManagement,
indexToInsertDependencyManagementTag,
dependencyManagementTagContents
)
Files.writeString(pomFilePath, fixedPomContent)
} else
logger.warn(
"Didn't find multiple <dependencyManagement> tag, " +
"maybe https://github.com/jfrog/build-info/issues/198 has been fixed " +
"or this project doesn't need this fix task anymore"
)
}
fun getFixedPomContent(
pomContent: String,
indexToInsertDependencyManagementTag: Int,
managedDependencies: List<String>
): String =
pomContent.substring(0, indexToInsertDependencyManagementTag) +
buildDependencyManagementTag(managedDependencies) +
pomContent.substring(indexToInsertDependencyManagementTag)
fun buildDependencyManagementTag(managedDependencies: List<String>) =
managedDependencies.joinToString(
separator = "",
prefix = "<dependencyManagement><dependencies>",
postfix = "</dependencies></dependencyManagement>"
)
tasks.findByName("generatePomFileForMavenJavaPublication")?.finalizedBy(fixPom)
?: logger.warn("Task 'generatePomFileForMavenJavaPublication' was not found in {}", tasks.names) |
How are you pulling in the dependencies? Which version of 'io.spring.dependency-management' are you using to run this? Seems like some versions do not have that method. |
@DerekWWestAwesomeDeveloper Which method? |
The workarounds for updating the pom file with custom tasks are ugly, the issue is simple: if you use The right solution would be to use one, for instance, to migrate all the BOMs usages from
to
|
) * SDI-318 Declare bom correctly with the dependencyManagement plugin See this thread: jfrog/build-info#198 (comment) * SDI-318 Remove
I'd rather get rid of |
For build.gradle, when using
in combination with
an invalid POM file is generated with two dependencyManagement elements. Deployment (artifactoryPublish) is thus refused by the artifactory server.
The text was updated successfully, but these errors were encountered: