How to send information from configuration phase to others?

Dear,

into my plugin I have build.gradle:

...
configuration{ reveng.extendsFrom(compile) }
dependencies {
    repositories {
        mavenCentral()
    }
    compile gradleApi()
    compile localGroovy()
    reveng "org.hibernate:hibernate-tools:4.3.1.CR1"
    reveng "org.slf4j:slf4j-simple:1.7.5"
    reveng "mysql:mysql-connector-java:5.1.34"
}

I do this to get after the corresponding classpath into my custom class Task

class RevengTask extends DefaultTask {
    ...
    def String classPath
    ...
      @TaskAction
    def run(){
          ...
        generateJava(project)
    }
      def generateJava(final Project project){
        project.ant {
            taskdef(name: 'hibernatetool',
                    classname: 'org.hibernate.tool.ant.HibernateToolTask',
                    classpath: classPath
)
            hibernatetool( destdir : hibernateDir, templatepath : 'templates' ) {
                jdbcconfiguration(
                        configurationfile:"${hibernateConfigXml.path}"
    ,
                        revengfile:"${hibernateRevEngXml.path}",
                        packagename:
                                "${projet.database.basePackage}"
                )
                hbm2java(
                        jdk5: true,
                        ejb3: true
                )
                classpath {
                    pathelement( path: "config" )
                }
            }
        }
    }
}

I tried here to use classPath properties which is defined like this:

class HibernatePlugin implements Plugin<Project>{
      @Override
    void apply(Project project) {
        ...
        project.task("reveng", type: RevengTask ) {
                ...
                classPath
         = configurations.reveng.asPath
        }
    }

but in this case configurations is not in the scope, and if i use project.configurations this will use the configuations from the project who apply this plugins and not the plugins project.

I think they are a trick to do but I am too new in gradle to understand where I fail.

thanks for your help

Typically this is solved by programmatically creating the configuration and dependencies on the project your plugin is being applied to, and reference it that way. So in your plugin you’d have a section that looked something like this.

def configuration = project.configurations.create(‘reveng’)

configuration.dependencies.add(project.dependencies.create(‘org.slf4j:slf4j-simple:1.7.5’))

Thanks you I will do it

you save me :slight_smile: