[JAVA-12746] Fix gradle-to-maven module to work with Gradle 7.x

This commit is contained in:
Haroon Khan 2022-06-23 09:53:16 +01:00
parent 1199ce0b12
commit 17b5c33d51
2 changed files with 60 additions and 19 deletions

View File

@ -3,39 +3,79 @@ repositories {
} }
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven' apply plugin: 'maven-publish'
group = 'com.baeldung' group = 'com.baeldung'
// by default, pom's artifactId is taken from the directory name // by default, pom's artifactId is taken from the directory name
version = '0.0.1-SNAPSHOT' version = '0.0.1'
dependencies { dependencies {
compile('org.slf4j:slf4j-api') implementation 'org.slf4j:slf4j-api:1.7.25'
testCompile('junit:junit') testImplementation 'junit:junit:4.12'
} }
install { // basic publishing
repositories {
mavenInstaller { //publishing {
pom.version = '0.0.1-maven-SNAPSHOT' // publications {
pom.groupId = 'com.baeldung.sample' // customLibrary(MavenPublication) {
pom.artifactId = 'gradle-maven-converter' // from components.java
pom.project { // }
inceptionYear '2020' // }
//
// repositories {
// maven {
// name = 'sampleRepo'
// url = layout.buildDirectory.dir("repo")
// }
// }
//}
// customized publishing
publishing {
publications {
customLibrary(MavenPublication) {
groupId = 'com.baeldung.sample'
artifactId = 'gradle-maven-converter'
version = '0.0.1-maven'
from components.java
pom {
name = 'Sample Library'
description = 'A description of sample library'
url = 'http://www.example.com/library'
licenses { licenses {
license { license {
name 'My License' name = 'The Apache License, Version 2.0'
url 'http://www.mycompany.com/licenses/license.txt' url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
} }
} }
} }
pom.whenConfigured {pom ->
pom.dependencies.find {dep -> dep.groupId == 'junit' && dep.artifactId == 'junit' }.optional = true pom.withXml {
asNode()
.dependencies
.dependency
.findAll { dependency ->
// find all dependencies with runtime scope
dependency.scope.text() == 'runtime'
}
.each { dependency ->
// set the scope to 'compile'
dependency.scope*.value = 'compile'
}
} }
pom.writeTo("${mavenPomDir}/${project.group}/${project.name}/pom.xml")
} }
} }
}
repositories {
maven {
name = 'sampleRepo'
url = layout.buildDirectory.dir("repo")
}
}
}

View File

@ -0,0 +1 @@
rootProject.name = 'gradle-to-maven'