diffplug / blowdryer

Keep your gradle builds dry 干

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fetching jar from classpath

nedtwigg opened this issue · comments

The next obvious feature after #12 is classpathJar, which could be implemented with something like this:

private static URL findResourceJar(String name) {
  ClassLoader loader = Blowdryer.class.getClassloader();
  while (loader != null) {
    if (loader instanceof URLClassLoader) {
      URL[] urls = urlLoader.getUrls();
      List<URL> matchingUrls = Arrays.stream(urls)
        .filter(url -> matches name)
        .collect(Collectors.toList());
      if (matchingUrls.size() == 1) {
        return matchingUrls.get(0);
      } else if (matchingUrls.isEmpty()) {
        throw "no matches"
      } else {
        throw "multiple matches " + matchingUrls
      }
    } else {
      loader = loader.getParent()
    }
  }
  throw "couldn't find URLClassLoader"
}

You could declare your plugin script jar in the settings.gradle plugins block. You could even put a little snippet of java code into your buildscripts jar which actually does blowdryerSetup { classpathJar ('myname') } for you automatically.

So in concrete terms this would look like:

// settings.gradle
plugins {
  id 'com.diffplug.blowdryerSetup' version '1.2.0'
  id 'com.acme.blowdryer-scripts' version '3.0.0'
}

blowdryerSetup {
  classpathJar('blowdryer-scripts')
}

But you could even simplify down to

// settings.gradle
plugins {
  id 'com.acme.blowdryer-scripts' version '3.0.0'
}

If your blowdryer-scripts jar has a single ConfigureBlowdryerPlugin.java which is just a Plugin<Settings> which does the blowdryerSetup part.

The classpathJar is exactly what I need, (or even better the simplified version), ... will this be implemented and released soon? Please! :-)

PR's welcome, but I have no plan to build this.