Using methods in scripts

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

Using methods in scripts

by Narco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello!
I want to use simple methods from subprojects{} but they can`t see actual project I`m in on runtime. For example:
subprojects {
usePlugin('java')
prepareJarResources()
}

void prepareJarResources(){
    println "Preparing Jar resources"

    sourceSets {
        main {
            resources {
                srcDir "main/resources/default"
                srcDir "src/resources/${configName}/default"
            }
        }
    }
}

Result:
Cause: Could not find method sourceSets() for arguments [build_gradle_ace5bd5145
ec9f80b1d9a7850f69c6b2$_prepareJarResources_closure3@1d590d] on root project 'MD
L'.

Re: Using methods in scripts

by Adam Murdoch-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Narco wrote:

> Hello!
> I want to use simple methods from subprojects{} but they can`t see actual
> project I`m in on runtime. For example:
> subprojects {
> usePlugin('java')
> prepareJarResources()
> }
>
> void prepareJarResources(){
>     println "Preparing Jar resources"
>
>     sourceSets {
>         main {
>             resources {
>                 srcDir "main/resources/default"
>                 srcDir "src/resources/${configName}/default"
>             }
>         }
>     }
> }
>
>  

The method runs with the root project as it's delegate, and as a result
cannot find the 'sourceSets' property. You will need to pass the target
project into the method, something like:

subprojects {
   prepareJarResources(delegate)
}

void prepareJarResources(def project) {
     project.sourceSets...
}

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


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

    http://xircles.codehaus.org/manage_email



Re: Using methods in scripts

by Narco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank You!

Adam Murdoch-2 wrote:
The method runs with the root project as it's delegate, and as a result
cannot find the 'sourceSets' property. You will need to pass the target
project into the method, something like:

subprojects {
   prepareJarResources(delegate)
}

void prepareJarResources(def project) {
     project.sourceSets...
}

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


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

    http://xircles.codehaus.org/manage_email