build.gradle - Gradle Custom buildScriptRepository methods -


i make custom buildscript repository method can reference our internal maven repo. right i'm required declare maven block everywhere use our plugin.

here current setup

buildscript {     repositories {         jcenter()         maven { url 'http://mynexus:8081/nexus/content/repositories/my-release' }     }      dependencies {         classpath 'com.example.plugin:my-plugin:1+'     } } 

what this

buildscript {     repositories {         jcenter()         myreleaserepo()     }      dependencies {         classpath 'com.example.plugin:my-plugin:1+'     } } 

how can make method available create repository anywhere may use plugin in future?

it possible add repo init script apply gradle invocations use init script - without having individually declare maven repo in each build.gradle.

solution 1:

partial solution, not exactly you're asking for. in init.gradle:

allprojects{     buildscript{         repositories{             maven{ url 'http://mynexus:8081/nexus/content/repositories/my-release' }         }     } } 

then build.gradle can skip buildscript repo declaration entirely:

buildscript {     dependencies {         classpath 'com.example.plugin:my-plugin:1+'     } } 

solution 2:

in fact, can move buildscript classpath declaration init , have plugin apply projects use init script:

beefier init.gradle

allprojects{     buildscript{         repositories{             maven{ url 'http://mynexus:8081/nexus/content/repositories/my-release' }         }         dependencies {             classpath 'com.example.plugin:my-plugin:1+'         }     } } 

gives lighter build.gradle

apply plugin: 'my-plugin' 

i tried to, apparently cannot move apply line init.gradle well. see this defect.

solution 3:

i retract said in comment above, figured out how exactly you're asking for. apparently can create extensions buildscript block using initscript. still prefer solution2, because gives cleaner build.gradle.

to create buildscript extension, in init.gradle:

class customrepos {     def buildscript       customrepos(buildscript) {         this.buildscript = buildscript     }      void addmyrepo() {         buildscript.repositories {             maven{ url 'http://mynexus:8081/nexus/content/repositories/my-release' }         }     } }  allprojects {     extensions.create('myrepo', customrepos, buildscript) } 

which allows in build.gradle

buildscript{     myrepo.addmyrepo()      dependencies {         classpath 'com.example.plugin:my-plugin:1+'     } }  apply plugin: 'my-plugin' 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -