Compile weirdness

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Compile weirdness

Steven Devijver
Dear Gradle friends,

It's been a very long time for me since I've been involved with Gradle. You've been doing a fantastic job over the past couple of months and the result is just stunning.

I've gotten hooked - again - to Gradle and started playing with it for fun and self-education. Right now I'm trying to port Spring from Ant to Gradle but I've run into some compile weirdnedd. This is why I'm seeking your help. I'm using Gradle 0.8.

I won't lay out the details of my entire setup, it's Gradle so it's pretty simple. I've uploaded a zip file containing the spring source and my build logic for those of you interested here:


The crux of the matter is this: I've added a project spring-beans which gets its source code from the big spring src/ directory. Normally my build file for spring-beans looks like this:

compileJava {
source = fileTree {
from src_dir
include "org/springframework/beans/**"
exclude "org/springframework/beans/factory/aspectj/**"
}
}

dependencies {
compile project(':src:spring-core')
compile ':cglib-nodep-2.1_3'
}


Pretty basic stuff, only it doesn't work. What happens, and you can try this yourself ("gradle clean build upload" from the project root), is that CompileJava is trying to compile files from the org.springframework.core package which it shouldn't touch and for which it is missing JARs on the class path.

I've changed my build file as follows and this does work:

compileJava.doFirst {
def temp_src_dir = file('build/temp/src')
temp_src_dir.mkdirs()

copy {
from src_dir
into temp_src_dir
include "org/springframework/beans/**"
exclude "org/springframework/beans/factory/aspectj/**"
}
}

compileJava {
source = fileTree('build/temp/src')
}

dependencies {
compile project(':src:spring-core')
compile ':cglib-nodep-2.1_3'
}

Works but doesn't look as slick. I'm at a loss to explain why the normal case doesn't work and why separating the intended code does work. The only thing I can think of is that the compiler first checks the source folder for classes it needs and only afterwards the class path. Is this a known problem? I've checked the issues in JIRA but nothing jumped me in the eye.

Thanks for your help

Steven

Reply | Threaded
Open this post in threaded view
|

Re: Compile weirdness

Adam Murdoch-2


Steven Devijver wrote:
Dear Gradle friends,

It's been a very long time for me since I've been involved with Gradle. You've been doing a fantastic job over the past couple of months and the result is just stunning.

I've gotten hooked - again - to Gradle and started playing with it for fun and self-education. Right now I'm trying to port Spring from Ant to Gradle but I've run into some compile weirdnedd. This is why I'm seeking your help. I'm using Gradle 0.8.

I won't lay out the details of my entire setup, it's Gradle so it's pretty simple. I've uploaded a zip file containing the spring source and my build logic for those of you interested here:


The crux of the matter is this: I've added a project spring-beans which gets its source code from the big spring src/ directory. Normally my build file for spring-beans looks like this:

compileJava {
source = fileTree {
from src_dir
include "org/springframework/beans/**"
exclude "org/springframework/beans/factory/aspectj/**"
}
}

dependencies {
compile project(':src:spring-core')
compile ':cglib-nodep-2.1_3'
}


Pretty basic stuff, only it doesn't work. What happens, and you can try this yourself ("gradle clean build upload" from the project root), is that CompileJava is trying to compile files from the org.springframework.core package which it shouldn't touch and for which it is missing JARs on the class path.

I've changed my build file as follows and this does work:

compileJava.doFirst {
def temp_src_dir = file('build/temp/src')

temp_src_dir.mkdirs()

copy {
from src_dir
into temp_src_dir
include "org/springframework/beans/**"
exclude "org/springframework/beans/factory/aspectj/**"
}
}

compileJava {
source = fileTree('build/temp/src')
}

dependencies {
compile project(':src:spring-core')
compile ':cglib-nodep-2.1_3'
}

Works but doesn't look as slick. I'm at a loss to explain why the normal case doesn't work and why separating the intended code does work. The only thing I can think of is that the compiler first checks the source folder for classes it needs and only afterwards the class path. Is this a known problem?

Yes. That's exactly what javac does.

To workaround the problem, you can use an empty sourcepath:

compileJava {
    options.compilerArgs = ['-sourcepath', '']
}


I've checked the issues in JIRA but nothing jumped me in the eye.


I've added http://jira.codehaus.org/browse/GRADLE-689

It's fixed in trunk.


-- 
Adam Murdoch
Gradle Developer
http://www.gradle.org
Reply | Threaded
Open this post in threaded view
|

Re: Compile weirdness

hans_d
Administrator
In reply to this post by Steven Devijver
Hi Steven,

On Oct 9, 2009, at 11:23 AM, Steven Devijver wrote:

Dear Gradle friends,

It's been a very long time for me since I've been involved with Gradle. You've been doing a fantastic job over the past couple of months and the result is just stunning.

Just wanna say that it is a great delight to hear from you and seeing you on the Gradle list again :)

- Hans

--
Hans Dockter
Gradle Project Manager