Hi,
We’ve recently moved my project from maven to gradle, and I must say, I am a fan!
However, I am seeing a problem with the jar manifest file in my project. I am generating a manifest file for the jar in my build as -
project(':myproject') {
jar {
manifest {
attributes 'Implementation-Title': 'My Project',
'Implementation-Version': project.version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Created-By': 'Gradle',
'Git-Commit': getSCMRevision(),
'Git-Branch': getSCMBranch()
}
}
}
where getSCMRevision() and getSCMBranch() are static methods that are exposed through a custom plugin.
After the build executes, the MANIFEST.MF file has all the right information, however, it seems to add one or more ‘^M’ characters at the end of every line. Due to this, when I try to execute a java command using a main class that is contained in this project’s jar, java errors as - ‘Error: Could not find or load main class’. This is presumably because the jar has a corrupt MANIFEST.MF. As soon as I unpack the jar, remove the ‘^M’ characters and rebuild the jar using ‘jar cf’, the java commands work.
I can see this error when I build both on OSX (Mavericks) as well as Centos 6.3. I am using gradle 1.11
If this has to do with file encoding, is there a recommended way of setting the encoding? Any other possible solutions to this?
Thanks, Bhooshan
---------------- UPDATE: This issue seems to occur because the methods ‘getSCMRevision()’ and ‘getSCMBranch()’ are defined in a custom plugin. If I remove these methods, the MANIFEST.MF file does not contain ^M characters. If I completely move the manifest definition to the custom plugin, I see the issue. If I define everything in my project’s build.gradle instead, I do not see the ^M characters. They seem to show up only if I invoke any functionality from the custom plugin in the manifest closure.
Any thoughts?