[GRADLE-2347] Jar created with incorrect name ending with '?.jar' when default version set in super project Created: 12/Jun/12  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-rc-3, 1.0
Fix Version/s: None

Type: Bug
Reporter: Daniel Joyce Assignee: Unassigned
Resolution: Won't Fix Votes: 0


 Description   

In the root master build.gradle, I do something like

def gitver = ""

new ByteArrayOutputStream().withStream { os ->
def result = exec

{ executable = 'git' args = ['describe','--tags','--always'] standardOutput = os }

gitver = os.toString()
}

project.version = gitver

println ''
println 'Determined version: '+rootProject.version

dependsOnChildren()

// Sub Project Configuration
subprojects

{ apply plugin: 'java' apply plugin: 'eclipse' sourceCompatibility = 1.6 group = 'foo.bar' // Default version, override in subproject build files... version = rootProject.version }

then, in a sub project, I have:

defaultTasks 'clean', 'jar'

apply plugin: 'java'

apply plugin: 'eclipse'

sourceCompatibility = 1.6

group = 'foo.bar'

test

{ useTestNG() }

dependencies

{ compile('com.alien:AlienRFID:2.2.7:@jar') compile('commons-configuration:commons-configuration:1.6@jar') testCompile 'org.testng:testng:5.10:jdk15' }

When I do a build in the subproject, I get a jar in the build/libs directory with a bad name

build/libs/subproject-version?.jar where version is the output of the git describe command.

The spurious "?" causes all sorts of problems.

If I set the version to a string in subprojects{} in the root project, then the jar is generated correctly w/o the "?".

using version="${rootProject.version}" in subprokjects doesn't work either.

If I print the value of version or rootProject.version out at any time, I see the correct value, without the spurious "?"

if I add the following to the subproject:
jar

{ classifier="DERP" }

in my subproject jar declaration, I get a jar project-version?-DERP.jar, still containing the spurious "?".

it seems more is going on than simply calling "toString" on the version object, which the docs imply.

I also tried a custom version object, initialized with value returned from git describe, and a simple toString method that simply echoed it out. Still doesn't work, the "?" still shows up.



 Comments   
Comment by Daniel Joyce [ 12/Jun/12 ]

rootProject.version = gitver.replaceAll("[^a-zA-Z0-9-.]","")

This fixes the issue. I suspect reading the output of git describe using a byteArrayStream likely messes with encodings, and thus we get some garbage characters in the version, though they print fine at the command prompt. Or it could be a carriage return at the end. I have yet to narrow it down.

Is there an easier way to read stdout from a command in Gradle?

Comment by Daniel Joyce [ 12/Jun/12 ]

adding os.toString("utf-8") doesn't fix it

but this also works

rootProject.version = gitver.replaceAll("\\s","")

So it must be the newline or something

Comment by Daniel Joyce [ 12/Jun/12 ]

Should have square brackets around
s looks like jira ate them.

Comment by Adam Murdoch [ 12/Jun/12 ]

os.toString().trim() would probably do the trick too.

Can I close this issue, as it doesn't look like a Gradle bug?

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:19:26 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.