Ant functionalities in Gradle


(Ganesh) #1

I am trying to compile and build a Java project for the very first time in Gradle and I am not able to achieve a few things.
Initially, I wrote an Ant xml to do the Jar creation for my project but I would now shift to Gradle. And I would like to know how to provide the following Ant functionalities in Gradle:

// build.xml from Ant
<project >

    <property environment="env"/>
    
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<target name="make">
<javac>
// defines srcs and other related arguments
		<classpath>
		<fileset dir="/data/products/libs/">
			<include name="**/*.jar"/>

			    </fileset>
		</classpath>
		<compilerarg compiler="org.eclipse.jdt.core.JDTCompilerAdapter" line="-1.8"/>
</javac>
</target>

Next is the build.gradle file

//build.gradle 
apply plugin: 'java'

sourceSets {
define the sources
}
dependencies {
	compile files ('/data/products/libs/**/*.jar')
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

jar {
	baseName = 'nsvf'
}

I am not sure how I can set the compiler args in Gradle like how I did in Ant. Thanks in advance for the help!


(Daniel Lacasse) #2

Hi Ganesh,

In order to configure the java compiler arguments, you need to configure them through the options property of compileJava task. See this documentation.

Daniel


(Ganesh) #3

Hi Daniel,

Thanks for the reply. However, I am unable to find out how to make Gradle use the JDTCompiler. In ant, I used the JDTCompilerAdapter using the following Ant commands:

<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>

So, how do I set this in Gradle? I cannot quite solve it by reading the options property in the DSL Reference.


(Daniel Lacasse) #4

This is a very good question Ganesh and I don’t think I have an answer for it. Maybe @bmuschko can pitch in an idea to answer this question?


(Benjamin Muschko) #5

AFAIK it’s not supported natively. This post describes a workaround.