I tried to generate a pom.xml that is similar to the Maven multi-project. Oddly enough, I noticed that “version” and “description” is not generated. I have created the build.gradle of minimum configuration, please look at this.
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
ext {
mavenRepository = "repository"
}
project.group = "com.test"
project.version = "1.0.0"
apply plugin: 'maven-publish'
createPom = {
parent {
groupId "org.sonatype.oss"
artifactId "oss-parent"
version "7"
}
name "Test Parent"
description "This is a test."
url "https://test.com/"
inceptionYear "2012"
modules {
module "test-library"
}
}
publishing {
publications {
maven(MavenPublication) {
artifactId "test-parent"
pom.withXml {
asNode().children().last() + createPom
}
}
}
repositories {
maven {
url(mavenRepository)
}
}
}
The following error occurs is this.
C:\Verify>gradle publish
Creating properties on demand (a.k.a. dynamic properties) has been deprecated an
d is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/c
urrent/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information
on the replacement for dynamic properties.
Deprecated dynamic property: "createPom" on "root project 'Verify'", value: "bui
ld_6gm9jhjtls60i9un...".
:generatePomFileForMavenPublication
:publishMavenPublicationToMavenRepository FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenPublicationToMavenRepository'.
> Failed to publish publication 'maven' to repository 'maven'
> Unable to initialize POM pom-default.xml: Missing version element from pare
nt element for project com.test:test-parent
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
Total time: 7.004 secs
“build/publications/maven/pom-default.xml” that have been generated.
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
</parent>
<name>Test Parent</name>
<url>https://test.com/</url>
<inceptionYear>2012</inceptionYear>
<modules>
<module>test-library</module>
</modules>
</project>
gralde may not be able to interpret them, but it should be output pom.xml as intended. Thanks.