Skip to content

Commit 3ac0bc7

Browse files
authored
Fix publish to maven local task (#1320)
1 parent b30cab4 commit 3ac0bc7

File tree

2 files changed

+60
-42
lines changed

2 files changed

+60
-42
lines changed

utbot-maven/build.gradle

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,69 @@ dependencies {
3535
* The plugin descriptor file is generated automatically by [generatePluginDescriptor].
3636
*/
3737

38-
def pomFile = file("./src/main/resources/pom.xml")
38+
def generatedPomFile = file("./build/resources/generated/pom.xml")
3939
def outputDirectory = project.buildDir.toPath().resolve("classes/kotlin/main")
4040
def pluginDescriptorFile = new File("$outputDirectory/META-INF/maven/plugin.xml")
4141

42+
/**
43+
* Generates the pom.xml file and saves it to the [generatedPomFile].
44+
*/
45+
task generatePomFile() {
46+
def rootNode = new Node(null, "project", [
47+
'xmlns': 'http://maven.apache.org/POM/4.0.0',
48+
'xsi:schemaLocation': 'http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd',
49+
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
50+
])
51+
52+
rootNode.with {
53+
appendNode('modelVersion', '4.0.0')
54+
appendNode('groupId', 'org.utbot')
55+
appendNode('artifactId', 'utbot-maven')
56+
appendNode('version', this.project.version)
57+
appendNode('packaging', 'maven-plugin')
58+
59+
appendNode('build').with {
60+
// paths relative to src/main/resources
61+
appendNode('directory', '../../../build')
62+
appendNode('outputDirectory', '../../../build/classes/kotlin/main')
63+
}
64+
65+
appendNode('dependencies').with {
66+
appendNode('dependency').with {
67+
appendNode('groupId', 'org.utbot')
68+
appendNode('artifactId', 'utbot-framework')
69+
appendNode('version', this.project.version)
70+
appendNode('scope', 'compile')
71+
}
72+
}
73+
}
74+
75+
def repositoriesNode = rootNode.appendNode('repositories')
76+
project.repositories.indexed().forEach { index, repository ->
77+
repositoriesNode.appendNode('repository').with {
78+
appendNode('id', "${repository.name}_${index}") // unique id
79+
appendNode('url', repository.url)
80+
}
81+
}
82+
83+
// creating `generatedPomFile` if it is not exist
84+
generatedPomFile.parentFile.mkdirs()
85+
generatedPomFile.createNewFile()
86+
87+
// printing xml content to `generatedPomFile`
88+
def printer = new XmlNodePrinter(new PrintWriter(new FileWriter(generatedPomFile)))
89+
printer.with {
90+
// pretty print
91+
preserveWhitespace = true
92+
expandEmptyElements = true
93+
}
94+
printer.print(rootNode)
95+
}
96+
4297
/**
4398
* Generates the plugin descriptor file and saves it to the [pluginDescriptorFile].
4499
*/
45-
task generatePluginDescriptor(type: JavaExec, dependsOn: compileKotlin) {
100+
task generatePluginDescriptor(type: JavaExec, dependsOn: [compileKotlin, generatePomFile]) {
46101
inputs.files project.compileKotlin.outputs.files
47102
outputs.file pluginDescriptorFile
48103

@@ -53,7 +108,7 @@ task generatePluginDescriptor(type: JavaExec, dependsOn: compileKotlin) {
53108
args = [
54109
'--errors',
55110
'--batch-mode',
56-
'--file', "${pomFile.path}",
111+
'--file', "${generatedPomFile.path}",
57112
'org.apache.maven.plugins:maven-plugin-plugin:3.6.0:descriptor',
58113
'-Dproject.build.sourceEncoding=UTF-8'
59114
]
@@ -77,15 +132,8 @@ publishing {
77132
* Therefore, we have to override the generated file with our own, stored in resources.
78133
*/
79134
generatePomFileForPluginMavenPublication.doLast {
80-
def ourOwnPomXml = new XmlParser().parse(pomFile)
81-
def generatedPomFile = new File("./build/publications/pluginMaven/pom-default.xml")
82-
def printer = new XmlNodePrinter(new PrintWriter(new FileWriter(generatedPomFile)))
83-
printer.with {
84-
// pretty print
85-
preserveWhitespace = true
86-
expandEmptyElements = true
87-
}
88-
printer.print(ourOwnPomXml)
135+
def pomFileFromMavenPublish = file("./build/publications/pluginMaven/pom-default.xml")
136+
pomFileFromMavenPublish.write(generatedPomFile.text)
89137
}
90138

91139
// the plugin jar file should contain the plugin descriptor file

utbot-maven/src/main/resources/pom.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)