On 29/07/2011, at 8:03 AM, AlanKrueger wrote:

> 
> TheKaptain wrote:
>> 
>> There's just a slight difference in the syntax between what you're trying
>> to do (add a new Task named jar) and configuring an existing one. If you
>> want to configure the one provided by default by the Java plugin, here's
>> the syntax:
>> jar {
>>                baseName = 'core'
>>                dependsOn classes
>>                from sourceSets.main.classes
>>                exclude('net/intellidata/core/**/*Impl*')
>> }
>> 
>> Hope that helps!
>> 
> I hesitate to resurrect this old thread, but I'm running into troubles
> trying something related to this.  I'm attempting to have the standard jar
> task only include Java classes, rather than also including resources
> directly in the jar file.
> 
> As such, I'm trying this:
> 
>    subprojects {
>        jar {
>            dependsOn classes
>            from sourceSets.main.classes
>            include '**/*.class'
>        }
>    }
> 
> We have a few subprojects, but the three that are involved in this are:
> 
>    Common <- Server <- Simulator
> 
> Where the <- indicates a compile dependency.  Without the declaration above,
> tests work correctly.  Adding that declaration, unit tests fail to see
> Server/src/main/resources files on the classpath.
> 
> We've taken to using this workaround, but this seems like a major hack:
> 
>    test.doFirst {
>        sourceSets.test.runtimeClasspath +=
> files(project(':Server').sourceSets.main.resources)
>    }
> 
> Any idea why this is happening?

The test task uses the jar of the target project for project dependencies. If 
the jar does not contain the resources, then the resources won't be visible to 
the test task in other projects.


>  Any suggestions how to handle this better?

Why do you want to exclude the resources from the jar? There might be another 
approach to solving that problem.

At some point, we want to change the test task to use sourceSets.main.output 
for project dependencies, rather than the jar. This would also solve your 
problem.


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com

Reply via email to