classpath for ant.java and project jar

View: New views
3 Messages — Rating Filter:   Alert me  

classpath for ant.java and project jar

by Philip Crotwell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am trying to create a task that will run java code that is built in
the current project. The user guide seems to indicate here:
http://gradle.org/0.8/docs/userguide/artifact_management.html#project_libraries
that the "default" configuration will be all runtime dependencies plus
archives. I assumed that this meant that the default java artifact jar
of my project would be part of "default" and so I could do something
like this:

task makeSodSite(dependsOn: jar)  << { task ->
    myArgs = '--run-once -p sod.prop'
    ant.java(dir:'build/output',
             classname:'edu.sc.seis.seiswww.MakeSite',
             args:myArgs,
             fork:true,
             classpath:configurations.default.asPath,
             output:project.projectDir.path+'/build/output/makeSodSite.out')
}

But it doesn't work, with a NoClassDefFoundError. I put in a few
prints, like this:
    println configurations.runtime.asPath
    println configurations.archives.asPath
    println configurations.default.asPath

and found that runtime and default seem to be identical and archives is empty.

Should the default artifact created by the java plugin be part of the
default configuration? Is there something besides depending on the jar
task that is required to get it there, or does it have to be done
manually? As an alternative, I could add "build/classes" to the
classpath manually, but that feels wrong to me.

Gradle 0.8

thanks,
Philip

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: classpath for ant.java and project jar

by Adam Murdoch-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Philip Crotwell wrote:

> I am trying to create a task that will run java code that is built in
> the current project. The user guide seems to indicate here:
> http://gradle.org/0.8/docs/userguide/artifact_management.html#project_libraries
> that the "default" configuration will be all runtime dependencies plus
> archives. I assumed that this meant that the default java artifact jar
> of my project would be part of "default" and so I could do something
> like this:
>
> task makeSodSite(dependsOn: jar)  << { task ->
>     myArgs = '--run-once -p sod.prop'
>     ant.java(dir:'build/output',
>              classname:'edu.sc.seis.seiswww.MakeSite',
>              args:myArgs,
>              fork:true,
>              classpath:configurations.default.asPath,
>  

Try:

classpath: sourceSets.main.runtimeClasspath.asPath

This will include build/main/classes, plus the dependencies in
configurations.runtime.

You should also change the dependsOn to

task makeSodSite(dependsOn: sourceSets.main.runtimeClasspath) << {
...
}

This will ensure everything in the runtimeClasspath has been built.

>              output:project.projectDir.path+'/build/output/makeSodSite.out')
> }
>
> But it doesn't work, with a NoClassDefFoundError. I put in a few
> prints, like this:
>     println configurations.runtime.asPath
>     println configurations.archives.asPath
>     println configurations.default.asPath
>
> and found that runtime and default seem to be identical and archives is empty.
>
> Should the default artifact created by the java plugin be part of the
> default configuration?

I think it should always include the jar. Oddly, if you add a project
dependency on the default configuration from another project, then it
does include the jar, but when you use it from the same project, it does
not include the jar.

Could you add a JIRA issue for this?


--
Adam Murdoch
Gradle Developer
http://www.gradle.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: classpath for ant.java and project jar

by hdockter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 10, 2009, at 2:52 AM, Adam Murdoch wrote:

>
>
> Philip Crotwell wrote:
>> I am trying to create a task that will run java code that is built in
>> the current project. The user guide seems to indicate here:
>> http://gradle.org/0.8/docs/userguide/artifact_management.html#project_libraries
>> that the "default" configuration will be all runtime dependencies  
>> plus
>> archives. I assumed that this meant that the default java artifact  
>> jar
>> of my project would be part of "default" and so I could do something
>> like this:
>>
>> task makeSodSite(dependsOn: jar)  << { task ->
>>    myArgs = '--run-once -p sod.prop'
>>    ant.java(dir:'build/output',
>>             classname:'edu.sc.seis.seiswww.MakeSite',
>>             args:myArgs,
>>             fork:true,
>>             classpath:configurations.default.asPath,
>>
>
> Try:
>
> classpath: sourceSets.main.runtimeClasspath.asPath
>
> This will include build/main/classes, plus the dependencies in  
> configurations.runtime.
>
> You should also change the dependsOn to
>
> task makeSodSite(dependsOn: sourceSets.main.runtimeClasspath) << {
> ...
> }
>
> This will ensure everything in the runtimeClasspath has been built.
>
>>             output:project.projectDir.path+'/build/output/
>> makeSodSite.out')
>> }
>>
>> But it doesn't work, with a NoClassDefFoundError. I put in a few
>> prints, like this:
>>    println configurations.runtime.asPath
>>    println configurations.archives.asPath
>>    println configurations.default.asPath
>>
>> and found that runtime and default seem to be identical and  
>> archives is empty.
>>
>> Should the default artifact created by the java plugin be part of the
>> default configuration?
>
> I think it should always include the jar. Oddly, if you add a  
> project dependency on the default configuration from another  
> project, then it does include the jar, but when you use it from the  
> same project, it does not include the jar.

This is the Ivy way of viewing the world which leaks into Gradle here.  
I agree that Gradle should behave differently here.

- Hans

--
Hans Dockter
Gradle Project Manager
http://www.gradle.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email