Gradle Guides - Creating Multi-project Builds

I hope this is the right place to post this :slight_smile:

I am totally new to gradle and was going through the gradle guide (Creating Multi-project Builds) from @Schalk_Cronje .

I ran into a problem which at first confused the heck out of me as someone who has never used Gradle or Groovy before. So I thought I would mention it here in case Schalk wants to add a hint to his guide :smile:

Following the documentation on my Windows machine I set up the GreetingFormatter/Greeter#main (Java) and the GreeterSpec (Groovy). The specification test kept blowing up on me on the simple string test-comparison:

class GreeterSpec extends Specification {

    def 'Calling the entry point'() {

        ...

        then: 'The correct greeting is output'
        buf.toString() == "Hello, Gradlephant\n"
    }
}

When the test failed and I compared the result with the expected I noticed that a CRLF linefeed was making the difference.

Java was using the System.lineSeparator Property from Windows (CRLF) and Groovy was just using the “\n” (not “\r\n”) in the test-string literal which lead to the two strings being unequal. I assume if this guide was followed on a Unix-Variant there would be no problem.

To get it to work I had to make one small change and add a “.denormalize()” to the Groovy String literal.

then: 'The correct greeting is output'
buf.toString() == 'Hello, Gradlephant\n'.denormalize()

Once I did that the specification test ran through.

1 Like

Thanks for reporting. The best place to open these issues is directly in the repository for that guide: https://github.com/gradle-guides/creating-multi-project-builds.

We usually just test the code of a guide on Linux with Travis CI. That’s probably why the issue wasn’t caught earlier. The assertion should probably use System.getProperty('line.separator') instead of \n. Alternatively, the assertion could be relaxed by using contains() instead.

1 Like

Thanks Benjamin, I created the issue on the other repository. Cheers, Jeff

Indeed! Unlike the native guides, then JVM ones are only tested on Linux.