Hi colleagues,
I am trying to migrate my project at work to the Gradle. We have quite an old code with directory layout not compatible with Java plugin (src/com/… src/test… etc…). . My idea was to make this migration quite smooth - first to use Gradle for dependency management and call our Ant tasks using Gradle. So, basically build.gradle would look like:
ant.importBuild 'build.xml'
repositories {
mavenCentral()
}
configurations { antdist }
dependencies {
antdist 'io.netty:netty:3.5.5.Final',
'javax.mail:mail:1.4.5'
}
ant.path(id:'classpath', location:configurations.antdist.asPath)
The monstrous construction “ant.path” is the only way I was able to force ant task “dist” working from the target below:
<target name="dist" depends="init">
<echo message="CLASSPATH=${toString:classpath}"/>
<echo message="JAVA CLASSPATH=${java.class.path}"/>
<javac srcdir="${src.dir}" destdir="${build.cls.dir}" nowarn="off" debug="on" failonerror="true" includeAntRuntime="false">
<classpath refid="classpath" />
<compilerarg value="-Xlint" />
<compilerarg value="-Werror" />
</javac>
<jar destfile="${dist.jar}" basedir="${build.cls.dir}">
<manifest>
<attribute name="Trusted-Only" value="true" />
</manifest>
</jar>
</target>
The strangest issue is, that if you left only one artifact in the dependency section (i. e. only ‘io.netty:netty:3.5.5.Final’), then everything works just fine. But if you add any more (second, thried, etc.), then the build is failed. It looks like Ant cannot find netty jar in the classpath at all.
C:\Work\tst>gradle dist
:clean
:init
:dist
[ant:echo] CLASSPATH=C:\{long path is omitted}\netty-3.5.5.Final.jar;C:\ {long path is omitted} \mail-1.4.5.jar;C:\
{long path is omitted} \activation-1.1.jar
[ant:echo] JAVA CLASSPATH=C:\{long path is omitted}\gradle-launcher-1.1.jar
C:\Work\tst\src\com\test\comm\IConnectionAdapter.java:3: error: package org.jboss.netty.channel does not exist
import org.jboss.netty.channel.Channel;
^
C:\Work\tst\src\com\test\comm\IConnectionAdapter.java:7: error: cannot find symbol
public void connectionCreated(Channel channel)
^
symbol:
class Channel
location: class IConnectionAdapter
...
I have added echo for the classpath, as you can see, and in the both cases (ant dist and gradle dist) it looks pretty the same, but javac doesn’t work from Gradle.
Can you help me to find the cause? Could you probably advise a better way to wrap existing Ant script? I would not like to add more configuration to the Gradle build-wrapper at the first step and would like to use its dependency management feature if possible.
Thank you in advance.