Custom task visibility vs init script


(MIGNEREY Pierre) #1

Hi,

I want to use a custom task defined in a external JAR.
This JAR is either coming from a maven repository or a flat dir according what is defined in my different init scripts.

In build.gradle

buildscript {
 repositories { customLibPath() }

 dependencies { classpath 'customTaskJar'}
}

task myTask(type: MyCustomTask) { 
  [...]
}

In init_script_1. gradle

buildscript.repositories.ext.customLibPath= {
	project.buildscript.repositories { maven {url javaCotsUrl} }
}

In init_script_2

buildscript.repositories.ext.customLibPath= {
	project.buildscript.repositories { flatDir { dirs "${javaCotsDir" } }
}

It works !

But I would like to move my task using my jar in a dedicated file and link it to the build.gradle with an apply from: ‘misc.gradle’

But

  • If I just move the task myTask into misc.gradle, I get " Could not get unknown property ‘MyCustomTask’"
  • If I move the buildscript block to the misc.gradle file in order to have visibility to the JAR, the customLibPath() fonction defined in init script is not seen

Could you help me.