How to use Exec type task to run javac command

Hello all,

I am currently testing how to implement the javac command in gradle on my local directory. My current test directory structure is:

my .java files that I want to compile are contained within:
“C:/Users/s7959615/Desktop/Technical_Work/gradle_test/com/bns/csm/downstream/basket/jaxb”

The destination directory of the generated .class files is:
“C:/Users/s7959615/Desktop/Technical_Work/gradle_test/classes/basket”

My (test) task currently is:

apply plugin: ‘java’

task javaComp (type:Exec) {
executable = “javac”
args = ["-sourcepath", “C:/Users/s7959615/Desktop/Technical_Work/gradle_test/com/bns/csm/downstream/basket/jaxb”,
“-d”, “C:/Users/s7959615/Desktop/Technical_Work/gradle_test/classes/basket”]
}

However it returns an error of:

Finished with non-zero exit value 2.

Any input would be appreciated.

Thanks,

Steven

Why use an Exec task to compile Java?

Just put your source code within src/main/java and it will compile automatically.
src/main/java/com/bns/csm/downstream/basket/jaxb

All you need is the java or java-libary plugin and it will compile all main and test java code.
src/main/java and src/test/java

plugins {
    id 'java-library'
}

I assume your gradle project is gradle_test? No need, nor should you use absolute paths like that. It will make it much more difficult to build anywhere else.

However if what you really want is to run the javac manually on some piece of code. Other than you should not use absolute paths, the arguments looks right, but Windows path has wrong file separator /, should be . C:\Users…
Try adding -verbose to find out more about why javac failed.