Need help to compile Java code in Gradle

(nvrbrkheart) #1


My requirement is:

I have 4 directories A, B, C and D. Each directory has the following subdirectories java/src and after compilation each directory produces a separate JAR file with the same name as the name of directory. for example A.jar, B.jar and so on.

How I can fulfill this requirement in Gradle.

I also want to generate the build folder under each directory. for example for directory A it should be A/build and for B it should be B/build and so on.

Also need to change the name of JAR i.e. same name as the name of directory

I am new to gradle. Please help me how I can achieve this.

Thanks, Sanjiv

(Peter Niederwieser) #2

Have a look at the “Multi-Project Builds” chapter in the Gradle User Guide and the multi-project build samples in the full Gradle distribution.

(nvrbrkheart) #3

Thanks Peter for showing right direction :slight_smile:

Can you please me in one more small question? I need to capture the Java Version and Gradle Version in MANIFEST.MF file as we did in ANT? Can you please help me on this?

Thanks, Sanjiv

(Peter Niederwieser) #4

See the docs for the Jar task, or similar posts in the forum.

(nvrbrkheart) #5

Can anybody please help me how to run the below command in gradle:

gradle -version | grep ^JVM

Thanks, Sanjiv

(René Groeschke) #6

not sure what you are trying, but I think

gradle -version | grep JVM

should do the trick.

regards, René

(nvrbrkheart) #7

Thanks Rene for quick response. Actually I am trying to extract the Java Version using this command. But the command after pipe symbol i.e. grep JVM or grep ^JVM did not work. I am not sure how to run the unix commands having pipe symbol in Gradle. This is my code:

task extarctVersion {

new ByteArrayOutputStream().withStream { os ->

def result = exec {

executable = ‘gradle’

args = [’-version’,’|’,‘grep JVM’]

standardOutput = os


output = os.toString()

} }

I also have tried following:


Thanks, Sanjiv

(René Groeschke) #8

This is a great conversation that’s separate from the main topic, so I created a new topic to continue the discussion. Please reference the new topic here: Getting java version of current gradle run