Need help getting uploadArchives working, using simplest Java plugin setup possible.
My first, simple goal is just to get uploadArchives to work for my sample Java project, which I purposefully made to be as simple as possible for educational purposes. Understanding that (other than uploadArchive/POM stuff) my Java project works perfectly well, including building the jar and running the generated program from it, very little from the Maven Plugin chapter of the user guide actually works, even when copy and pasting sample code. Most critically, I have never had uploadArchives complete because it ALWAYS aborts with:
Cause: Unable to initialize POM pom-default.xml: Failed to validate POM for project grpId:gramvn at /home/blaine/tmp/gramvn/build/poms/pom-default.xml
I understand that Gradle uses the Maven Ivy tasks underneath, but what a piece-of-crap validator that gives you no clue about what specifically failed to validate, even when run with debug logging? Since Gradle is generating this POM, implicitly, you would think it would generate the POM in such a form as to satisfy the validator that it is immediately going to run on it. This happens when I set no modifications, to use all defaults, and I have had no success by adding POM settings (from user guide and other configurations found on Internet) in an attempt to force Gradle to write a POM more palatable to itself.
My problem is pretty much GRADLE-1114, except that the Comments in that issue do not apply to me (using milestone 3).
I am only referencing dependencies which are available and I am attempting to publish to a local repository, and these are the only things that Hans and Lucas have any problem with. Note that my setup is more simple than the test case supplied in this Issue because mine is a simple top-level project with no nesting/sub-projects.
Since the validator gives no useful information, I don’t know if the validation is failing because of the missing “packaging” element, as described in GRADLE-1200. In the case of GRADLE-1200 the author is generating the POM explicitly, not implicitly by uploadArchives, but both his and my (implicitly generated) output POM files lack the packaging element. Unfortunately, I don’t know if lack of “packaging” results in the Gradle validation failure since the issue author says nothing about that. Could be that Gradle is satisfied with it but the Sonatype or whatever server doesn’t like Gradle’s POM. I have tried the total hack of a work-around for GRADLE-1200 at http://www.mail-archive.com/user@gradle.codehaus.org/msg05389.html , but copy and pasting the relevant code doesn’t add to the implicitly-generated POM at all. Therefore, I know of no way to get the packaging element inserted into the POM to eliminate that as possible cause of validation failure. (I also see that the explicit POM creation, done by copy and pasting the writeNewPom example from the user guide, also gets no packaging element). Maybe the packaging element is just a huge red herring, but what else…???
The related problems that I see discussed are related to nested projects, Sonatype, or Artifactory, but as I said, my setup is extremely simple: I am using only Java and Maven plugins and am just trying to publish to a local file repository.
I do have a build.gradle that includes all of the attempted fixes and configurations that I have found in forums, Jira, and user guide, but to keep this post short I’ll post here just my basic build.gradle which I have attempted to construct as instructed in the Maven Plugin chapter of the user guide:
apply plugin: 'java'
apply plugin: 'maven'
defaultTasks 'run'
repositories {
mavenCentral()
flatDir dirs: (
new File(System.properties['user.home'], 'webapp-base/local/repos'))
}
dependencies {
compile(
[group: 'commons-logging', name: 'commons-logging', version: '1.1.1']
) { transitive = false }
runtime(
[group: 'commons-logging', name: 'commons-logging', version: '1.1.1'],
[name: 'org.springframework.core', version: '3.1.0.M1']
//) { transitive = false }
Why the hell doesn't this work?
)
}
task(rtjars, type: Copy).from(configurations.runtime.files).into(libsDir)
task setman (dependsOn: rtjars) << {
println '================================'
def deplibs = []
configurations.runtime.files.collect { deplibs << it.name }
println 'DEPLIBS: ' + deplibs.join(' ')
jar { manifest {
attributes( 'main-class': 'pkga.Main',
'class-path': deplibs.join(' ')
) } }
}
jar.dependsOn << setman
task run (dependsOn: assemble) << {
println configurations.runtime.files
javaexec { main = '-jar'; args = [jar.archivePath, 'par1', 'par2'] }
}
uploadArchives {
repositories.mavenDeployer {
repository(url: "file://tmp/fake-repos/")
}
}
// Required by uploadArchives:
group = 'grpId'
organization = 'Me'