source set questions

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

source set questions

by Steve Appling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to update the root build.gradle to handle some of my recent changes
and am running past my understanding of source sets.

The javadoc task currently has:
srcDirs = subprojects.inject([]) {list, project -> list +
project.source.main.java.srcDirs + project.source.main.groovy.srcDirs}

I have changed a sub-project to not be a groovy project and am trying to build
up the correct set of sources for javadoc, but I can't figure out how to test
what kind of sources are in a SourceSet. If I reference
project.source.main.groovy I get an exception on non-groovy projects.

project.source.main.groovy is not always valid - actually, I don't understand
why it is ever valid, getGroovy is not a part of the SourceSet interface but is
injected dynamically in some way that I couldn't follow.  SourceSet.getJava is
always part of the interface, but seems odd for a Groovy project.

--
Steve Appling
Automated Logic Research Team

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

    http://xircles.codehaus.org/manage_email



Re: source set questions

by Adam Murdoch-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Steve Appling wrote:

> I'm trying to update the root build.gradle to handle some of my recent
> changes and am running past my understanding of source sets.
>
> The javadoc task currently has:
> srcDirs = subprojects.inject([]) {list, project -> list +
> project.source.main.java.srcDirs + project.source.main.groovy.srcDirs}
>
> I have changed a sub-project to not be a groovy project and am trying
> to build up the correct set of sources for javadoc, but I can't figure
> out how to test what kind of sources are in a SourceSet. If I
> reference project.source.main.groovy I get an exception on non-groovy
> projects.
>

The intended solution is that tasks such as javadoc or checkstyle which
operate on Java source use the SourceSet.allJava property, which is a
FileTree containing all Java source files regardless of the type of
project, and where the source comes from. Something like:

javadoc {
    subprojects.each {
        source it.source.main.allJava
    }
}

At the moment, Javadoc does not accept a FileCollection as source (it
will soon), so we're stuck with reverse engineering the source
directories. You could do something like:

srcDirs = subprojects.inject([]) {list, project ->
    if ( project.source.main.hasProperty('groovy') {
        list.addAll(project.source.main.groovy.srcDirs)
    }
    list.addAll(project.source.main.java.srcDirs)
}

> project.source.main.groovy is not always valid - actually, I don't
> understand why it is ever valid, getGroovy is not a part of the
> SourceSet interface but is injected dynamically in some way that I
> couldn't follow.  SourceSet.getJava is always part of the interface,
> but seems odd for a Groovy project.
>

Some documentation is coming, but, basically, SourceSet is extended by
plugins using exactly the same mechanism they use to extend Project. The
groovy plugin mixes in GroovySourceSet to each source set. This is where
the groovy property comes from.


Adam


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

    http://xircles.codehaus.org/manage_email



Re: source set questions

by Steve Appling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Adam Murdoch wrote:

>
>
> Steve Appling wrote:
>> I'm trying to update the root build.gradle to handle some of my recent
>> changes and am running past my understanding of source sets.
>>
>> The javadoc task currently has:
>> srcDirs = subprojects.inject([]) {list, project -> list +
>> project.source.main.java.srcDirs + project.source.main.groovy.srcDirs}
>>
>> I have changed a sub-project to not be a groovy project and am trying
>> to build up the correct set of sources for javadoc, but I can't figure
>> out how to test what kind of sources are in a SourceSet. If I
>> reference project.source.main.groovy I get an exception on non-groovy
>> projects.
>>
>
> The intended solution is that tasks such as javadoc or checkstyle which
> operate on Java source use the SourceSet.allJava property, which is a
> FileTree containing all Java source files regardless of the type of
> project, and where the source comes from. Something like:
>
> javadoc {
>    subprojects.each {
>        source it.source.main.allJava
>    }
> }
>
> At the moment, Javadoc does not accept a FileCollection as source (it
> will soon), so we're stuck with reverse engineering the source
> directories. You could do something like:
>
> srcDirs = subprojects.inject([]) {list, project ->
>    if ( project.source.main.hasProperty('groovy') {
>        list.addAll(project.source.main.groovy.srcDirs)
>    }
>    list.addAll(project.source.main.java.srcDirs)
> }
This is actually very similar to what I was trying, but:
    project.source.main.hasProperty('groovy') returns 'null' for gradle-core.
Something is wrong here - not sure what.

>
>> project.source.main.groovy is not always valid - actually, I don't
>> understand why it is ever valid, getGroovy is not a part of the
>> SourceSet interface but is injected dynamically in some way that I
>> couldn't follow.  SourceSet.getJava is always part of the interface,
>> but seems odd for a Groovy project.
>>
>
> Some documentation is coming, but, basically, SourceSet is extended by
> plugins using exactly the same mechanism they use to extend Project. The
> groovy plugin mixes in GroovySourceSet to each source set. This is where
> the groovy property comes from.
>
>
> Adam
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

--
Steve Appling
Automated Logic Research Team

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

    http://xircles.codehaus.org/manage_email



Re: source set questions

by Adam Murdoch-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Steve Appling wrote:

>
>
> Adam Murdoch wrote:
>>
>>
>> Steve Appling wrote:
>>> I'm trying to update the root build.gradle to handle some of my
>>> recent changes and am running past my understanding of source sets.
>>>
>>> The javadoc task currently has:
>>> srcDirs = subprojects.inject([]) {list, project -> list +
>>> project.source.main.java.srcDirs + project.source.main.groovy.srcDirs}
>>>
>>> I have changed a sub-project to not be a groovy project and am
>>> trying to build up the correct set of sources for javadoc, but I
>>> can't figure out how to test what kind of sources are in a
>>> SourceSet. If I reference project.source.main.groovy I get an
>>> exception on non-groovy projects.
>>>
>>
>> The intended solution is that tasks such as javadoc or checkstyle
>> which operate on Java source use the SourceSet.allJava property,
>> which is a FileTree containing all Java source files regardless of
>> the type of project, and where the source comes from. Something like:
>>
>> javadoc {
>>    subprojects.each {
>>        source it.source.main.allJava
>>    }
>> }
>>
>> At the moment, Javadoc does not accept a FileCollection as source (it
>> will soon), so we're stuck with reverse engineering the source
>> directories. You could do something like:
>>
>> srcDirs = subprojects.inject([]) {list, project ->
>>    if ( project.source.main.hasProperty('groovy') {
>>        list.addAll(project.source.main.groovy.srcDirs)
>>    }
>>    list.addAll(project.source.main.java.srcDirs)
>> }
> This is actually very similar to what I was trying, but:
>    project.source.main.hasProperty('groovy') returns 'null' for
> gradle-core. Something is wrong here - not sure what.
>>

There's a few other ways you can check if the groovy plugin has been
applied:

project.plugins.hasPlugin('groovy')
project.source.main.convention.plugins.groovy


Adam


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

    http://xircles.codehaus.org/manage_email