@@ -3,39 +3,79 @@ repositories {
33}
44
55apply plugin : ' java'
6- apply plugin : ' maven'
6+ apply plugin : ' maven-publish '
77
88group = ' com.baeldung'
99
1010// by default, pom's artifactId is taken from the directory name
1111
12- version = ' 0.0.1-SNAPSHOT '
12+ version = ' 0.0.1'
1313
1414dependencies {
15- compile( ' org.slf4j:slf4j-api' )
16- testCompile( ' junit:junit' )
15+ implementation ' org.slf4j:slf4j-api:1.7.25 '
16+ testImplementation ' junit:junit:4.12 '
1717}
1818
19- install {
20- repositories {
21- mavenInstaller {
22- pom. version = ' 0.0.1-maven-SNAPSHOT'
23- pom. groupId = ' com.baeldung.sample'
24- pom. artifactId = ' gradle-maven-converter'
25- pom. project {
26- inceptionYear ' 2020'
19+ // basic publishing
20+
21+ // publishing {
22+ // publications {
23+ // customLibrary(MavenPublication) {
24+ // from components.java
25+ // }
26+ // }
27+ //
28+ // repositories {
29+ // maven {
30+ // name = 'sampleRepo'
31+ // url = layout.buildDirectory.dir("repo")
32+ // }
33+ // }
34+ // }
35+
36+ // customized publishing
37+
38+ publishing {
39+ publications {
40+ customLibrary(MavenPublication ) {
41+ groupId = ' com.baeldung.sample'
42+ artifactId = ' gradle-maven-converter'
43+ version = ' 0.0.1-maven'
44+
45+ from components. java
46+
47+ pom {
48+ name = ' Sample Library'
49+ description = ' A description of sample library'
50+ url = ' http://www.example.com/library'
2751 licenses {
2852 license {
29- name ' My License'
30- url ' http://www.mycompany.com/licenses/license.txt'
31- distribution ' repo'
53+ name = ' The Apache License, Version 2.0'
54+ url = ' http://www.apache.org/licenses/LICENSE-2.0.txt'
3255 }
3356 }
3457 }
35- pom. whenConfigured {pom ->
36- pom. dependencies. find {dep -> dep. groupId == ' junit' && dep. artifactId == ' junit' }. optional = true
58+
59+ pom. withXml {
60+ asNode()
61+ .dependencies
62+ .dependency
63+ .findAll { dependency ->
64+ // find all dependencies with runtime scope
65+ dependency. scope. text() == ' runtime'
66+ }
67+ .each { dependency ->
68+ // set the scope to 'compile'
69+ dependency. scope* . value = ' compile'
70+ }
3771 }
38- pom. writeTo(" ${ mavenPomDir} /${ project.group} /${ project.name} /pom.xml" )
3972 }
4073 }
41- }
74+
75+ repositories {
76+ maven {
77+ name = ' sampleRepo'
78+ url = layout. buildDirectory. dir(" repo" )
79+ }
80+ }
81+ }
0 commit comments