Skip to content

Fix publish to maven local task #1320

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

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 60 additions & 12 deletions utbot-maven/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,69 @@ dependencies {
* The plugin descriptor file is generated automatically by [generatePluginDescriptor].
*/

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

/**
* Generates the pom.xml file and saves it to the [generatedPomFile].
*/
task generatePomFile() {
def rootNode = new Node(null, "project", [
'xmlns': 'http://maven.apache.org/POM/4.0.0',
'xsi:schemaLocation': 'http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
])

rootNode.with {
appendNode('modelVersion', '4.0.0')
appendNode('groupId', 'org.utbot')
appendNode('artifactId', 'utbot-maven')
appendNode('version', this.project.version)
appendNode('packaging', 'maven-plugin')

appendNode('build').with {
// paths relative to src/main/resources
appendNode('directory', '../../../build')
appendNode('outputDirectory', '../../../build/classes/kotlin/main')
}

appendNode('dependencies').with {
appendNode('dependency').with {
appendNode('groupId', 'org.utbot')
appendNode('artifactId', 'utbot-framework')
appendNode('version', this.project.version)
appendNode('scope', 'compile')
}
}
}

def repositoriesNode = rootNode.appendNode('repositories')
project.repositories.indexed().forEach { index, repository ->
repositoriesNode.appendNode('repository').with {
appendNode('id', "${repository.name}_${index}") // unique id
appendNode('url', repository.url)
}
}

// creating `generatedPomFile` if it is not exist
generatedPomFile.parentFile.mkdirs()
generatedPomFile.createNewFile()

// printing xml content to `generatedPomFile`
def printer = new XmlNodePrinter(new PrintWriter(new FileWriter(generatedPomFile)))
printer.with {
// pretty print
preserveWhitespace = true
expandEmptyElements = true
}
printer.print(rootNode)
}

/**
* Generates the plugin descriptor file and saves it to the [pluginDescriptorFile].
*/
task generatePluginDescriptor(type: JavaExec, dependsOn: compileKotlin) {
task generatePluginDescriptor(type: JavaExec, dependsOn: [compileKotlin, generatePomFile]) {
inputs.files project.compileKotlin.outputs.files
outputs.file pluginDescriptorFile

Expand All @@ -53,7 +108,7 @@ task generatePluginDescriptor(type: JavaExec, dependsOn: compileKotlin) {
args = [
'--errors',
'--batch-mode',
'--file', "${pomFile.path}",
'--file', "${generatedPomFile.path}",
'org.apache.maven.plugins:maven-plugin-plugin:3.6.0:descriptor',
'-Dproject.build.sourceEncoding=UTF-8'
]
Expand All @@ -77,15 +132,8 @@ publishing {
* Therefore, we have to override the generated file with our own, stored in resources.
*/
generatePomFileForPluginMavenPublication.doLast {
def ourOwnPomXml = new XmlParser().parse(pomFile)
def generatedPomFile = new File("./build/publications/pluginMaven/pom-default.xml")
def printer = new XmlNodePrinter(new PrintWriter(new FileWriter(generatedPomFile)))
printer.with {
// pretty print
preserveWhitespace = true
expandEmptyElements = true
}
printer.print(ourOwnPomXml)
def pomFileFromMavenPublish = file("./build/publications/pluginMaven/pom-default.xml")
pomFileFromMavenPublish.write(generatedPomFile.text)
}

// the plugin jar file should contain the plugin descriptor file
Expand Down
30 changes: 0 additions & 30 deletions utbot-maven/src/main/resources/pom.xml

This file was deleted.