Gradle JAR task not working after upgrading from 0.92 to 2.1

Here is my gradle.build script,

apply plugin: ‘java’

task testJar(type: Jar) {

println sourceSets.test.output.classesDir

archiveName = ‘rjs-tests.jar’

from sourceSets.test.output }

i am using gradle 2.1

Without more information, it’s impossible to say what the problem is. Note that a clean build is required whenever you switch Gradle versions. You can also try to delete the ‘.gradle’ directory.

The thing is i am not getting any error in running this script so actually whont be able to figure out the exact issue.

I am running the below command -

gradle clean build

Try with ‘–info’ or ‘–debug’ logging.

Hi Garvit
Thanks for supplying the build file. I just tried with 2.1 and received build successful with the archive created.
Can you please advise what is not working?
Thanks
Kon

Have you got the archive file created? i am also getting a file created by the name of the parent folder but not with the name specified.

Try and open the jar it only have a default manifest file.

can’t we use

Jar{

}

task multiple times in a build.gradle file.

Hi Garvit

Have the rjs-tests.jar created in build/libs/rjs-tests.jar
I only copied and pasted your build file so no tests to put in.

jar { … } is a convention mapping, not a task itself, so if you wanted multiple jars in the same build file, you’d need to create separate jar tasks.  Otherwise your multiple jar {} blocks are just configuring the default

gradle jar

task

As Rene mentioned in another thread, as you are jumping quite far in versions (3years apart), you may want to migrate from an 0.x to a 1.x release first, then to 2.x.  You can try gvmtool.net to switch different versions at the command line to help you set a different gradle at the command line as you migrate up.  Make sure everything is working at 1.x version before jumping straight to 2.x.  

Also looking at the release notes to see whats changed between versions will help http://www.gradle.org/docs/current/release-notes

Hope that helps
Kon

Hi Kon,

Thanks for your reply yesterday, i dont understand why the jar type task is not working i tried with gradle 1.5 also and i face the similar issue.

while it is working with 0.9.2 version.

This reply was created from a merged topic originally titled Gradle Jar task not working after upgrade from 0.9.2 to 2.1 version. Hi, i am upgrading from 0.9.2 to 2.1 version but the jar task is not working, below is my gradle.build file -

apply plugin: ‘java’

task testJar(type: Jar) {

archiveName = ‘abc.jar’

}

The same code is working with gradle version 0.9.2 but not with gradle version 1.5 or gradle version 2.1

Please check and let me know, if i need to change this in order to make this work with 1.5 or 2.1 gradle versions.

I don’t see anything wrong with this, except that it will produce an empty Jar because no contents are defined.

Empty jar is ok,

I have creates a separate project and keep this build file in it and run this with gradle 0.9.2 version and it works a empty jar with name abc.jar gets created but when i run the same script with gradle 1.5 or with 2.1 version the empty jar is not getting created. :frowning:

Can you share a simple jar task which you have working on gradle 2.1.

Your script works fine with 2.1, and creates an (almost) empty ‘build/libs/abc.jar’. If it doesn’t work for you (i.e. no error but no Jar created), I recommend to try on a different machine, to rule out problems with your local environment.

ok let me try that.

Peter i have cleaned up everything and run this on a different machine, still only the default jar is getting created and no abc.jar is there.

Is gradle2.1 supported on windows7.

Yes it is. Are you running ‘gradle testJar’? ‘gradle build’ will not run ‘testJar’ (without adding some task dependency).

Yes i am running “gradle clean build” and this command works in 0.9.2 but not in 2.1.

From what I remember, in old Gradle versions ‘assemble’ (which ‘build’ depends on) used to build all Jars. This is no longer the case, but you can get back this behavior with, say, ‘assemble.dependsOn(“testJar”)’. Depending on what exactly the test Jar is used for, and why you want ‘gradle build’ to build it, a different solution might be more appropriate.