How to implement inheritance when parent project is stored in repository?


(vitali kviatkouski) #1

Are there ways to implement inheritance (like in maven) from some parent project where project is redistributed by maven/ivy repository? As I found out, there several ways: 1. use apply from - not suitable, need automatic publication and distribution by repo, should have no imports by direct addresses (file/http) 2. use custom plugin - seems to be the solution, but I want something more clear as simple gradle script file. Also have trouble with running pmd plugin with custom ruleset. Ruleset is packaged in plugin jar and can’t be reached in runtime build (http://forums.gradle.org/gradle/topics/cant_add_custom_ruleset_to_pmd_plugin_when_ruleset_is_inside_jar_file)


(Peter Niederwieser) #2

You’ve pretty much listed the options. In the future we might offer something with the ease of 1. and the distribution options of 2. The good news is that 2. isn’t really that much harder. In particular, you can use almost all the build script syntax when implementing a plugin class too, with the following “trick”:

class MyPlugin implements Plugin<Project> {
  void apply(Project project) {
    project.configure(project) { // this is the important line
      repositories { ... }
      dependencies { ... }
      task(name: "copy", type: Copy) { ... } // slight deviation from build script syntax
      ...
    }
  }
}