Plugin task configuration section can't see values from extension object

I’m new at gradle, and having a problem setting up a Copy task in my custom plugin. I’m using an extension object to configure the into location for my Copy task, and when I execute the script files are copied. However, the destination directory is named ‘null/modules/null’ instead of the value that was configured.

project.task('copySourceToBuild', type: Copy) {
 from "src"
 into "${project.jsConfig.buildWorkingDir}/modules/${project.jsConfig.libraryName}"
}

If I manually copy the exact same task into my build.gradle file, the value is correctly seen, and directory created. My plugin doesn’t seem to be able to see the value inside the configure section, but can inside of doLast{}.

Are you applying your plugin before you applied your extension?

It’s an often discussed topic here and on Stack Overflow. Plugins have to defer reading any mutable build model property until at least the end of the configuration phase. There are various techniques for doing so. Best places to learn are earlier discussions and/or the Gradle codebase.

Thanks Peter, I’ll look for discussions about that.

Hi Timothy, This link helpful to you http://code4reference.com/2012/08/gradle-custom-plugin-part-2/

I ended up changing it to this, and it is working great:

project.task('copySourceToBuild', type: Copy) {
 project.gradle.projectsEvaluated {
  from "src"
  into "${extension.buildWorkingDir}/modules/${extension.libraryName}"
   }
}