Inject 'Settings' plugin from 'mavenLocal()' into source dependency

I have a source dependency that isn’t built by Gradle into which I would like to inject a Settings plugin. I’m still developing this plugin, so I’m currently publishing it to mavenLocal().

Conceptually, I would like to do the following in my main project:

// settings.gradle

sourceControl {
    gitRepository("https://github.com/tudortimi/svunit.git") {
        producesModule("org.svunit:svunit")
        plugins {
            id 'com.verificationgentleman.gradle.hdvl.svunit-build' version '0.1.0-SNAPSHOT'
        }
    }
}

The doc for VersionControlRepository.plugins(...) says that injected plugins must be located in the calling build’s buildSrc project. This native sample shows that it’s also possible to inject plugins defined in included builds.

I thought I was going to game the system by defining a local plugin that just applies the aforementioned plugin from mavenLocal().

I created a new plugins directory, which I included in the main build. I added an empty settings.gradle file to have Gradle treat it as an own project. I made it a Gradle plugin build:

// plugins/build.gradle

plugins {
    id 'groovy'
    id 'java-gradle-plugin'
}

gradlePlugin {
    plugins {
        "local-svunit-build" {
            id = "local-svunit-build"
            implementationClass = "com.verificationgentleman.tgen.gradle.LocalSVUnitBuildPlugin"
        }
    }
}

The goal was to inject this plugin in the main settings.gradle:

sourceControl {
    gitRepository("https://github.com/tudortimi/svunit.git") {
        producesModule("org.svunit:svunit")
        plugins {
            'local-svunit-build'
        }
    }
}

I added the following code to the implementation class:

class LocalSVUnitBuildPlugin implements Plugin<Settings> {
    void apply(Settings settings) {
        settings.apply plugin: "com.verificationgentleman.gradle.hdvl.svunit-build"
    }
}

I get the following exception:

An exception occurred applying plugin request [id: 'local-svunit-build']
> Failed to apply plugin 'local-svunit-build'.
   > Plugin with id 'com.verificationgentleman.gradle.hdvl.svunit-build' not found.

I figured this was because mavenLocal() was missing as a repository from the ‘plugins’ project. I tried adding the following lines to the build file:

repositories {
    mavenLocal()
}

No luck. I figured that maybe the issue was that Gradle didn’t know exactly how to handle the svunit-build plugin version. I added a dependency on it to the classpath:

dependencies {
    runtimeClasspath "com.verificationgentleman.gradle:gradle-hdvl:0.1.0-SNAPSHOT"
}

(I’m using IntelliJ IDEA and the project is integrated with Gradle. It shows me that the dependency is properly resolved. The jar also has a properties file which specifies the implementation class for com.verificationgentleman.gradle.hdvl.svunit-build.)

I still get the error.

Does anyone have any idea what I’m doing wrong?

I also tried to apply the svunit-build plugin using its class, instead of the id. To do this, I changed the dependency to be on compileClasspath:

dependencies {
    compileClasspath "com.verificationgentleman.gradle:gradle-hdvl:0.1.0-SNAPSHOT"
}

In the implementation class I did the following:

import com.verificationgentleman.gradle.hdvl.svunit.SVUnitBuildPlugin

class LocalSVUnitBuildPlugin implements Plugin<Settings> {
    void apply(Settings settings) {
        settings.apply plugin: SVUnitBuildPlugin.class
    }
}

This compiles, but when I try to run it I get:

FAILURE: Build failed with an exception.

* What went wrong:
com/verificationgentleman/gradle/hdvl/svunit/SVUnitBuildPlugin
> com.verificationgentleman.gradle.hdvl.svunit.SVUnitBuildPlugin

Also, the reason I put the local-svunit-plugin in an included build and not in buildSrc is because if I put it in buildSrc Gradle complains that it can’t find it when it tries to inject it.

I revisited my attempt of applying svunit-build using its class. I read up a bit on Java compilation and I figured out that I was using the wrong configuration when specifying the dependency. compileClasspath will only put it on the classpath for compilation, but not for runtime, which is probably the reason I got the error.

I replaced it with the implementation configuration:

dependencies {
    implementation "com.verificationgentleman.gradle:gradle-hdvl:0.1.0-SNAPSHOT"
}

Now its failing while configuring the project with the following error:

Populating VCS workingDir svunit_7ws23phch0qgsj38d72o2y38f/svunit with ref v3.34.2: f519678f7ec881c1ac4844590a21db682a243e17
Resource missing. [HTTP GET: https://jcenter.bintray.com/com/verificationgentleman/gradle/gradle-hdvl/0.1.0-SNAPSHOT/maven-metadata.xml]
Resource missing. [HTTP HEAD: https://jcenter.bintray.com/com/verificationgentleman/gradle/gradle-hdvl/0.1.0-SNAPSHOT/gradle-hdvl-0.1.0-SNAPSHOT.pom]

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all artifacts for configuration 'classpath'.
> Could not find com.verificationgentleman.gradle:gradle-hdvl:0.1.0-SNAPSHOT.
  Searched in the following locations:
    - https://plugins.gradle.org/m2/com/verificationgentleman/gradle/gradle-hdvl/0.1.0-SNAPSHOT/maven-metadata.xml
    - https://plugins.gradle.org/m2/com/verificationgentleman/gradle/gradle-hdvl/0.1.0-SNAPSHOT/gradle-hdvl-0.1.0-SNAPSHOT.pom
  Required by:
      unspecified:unspecified:unspecified > project :plugins

It seems to me that for the injected project for the svunit source dependency Gradle is only looking in the Plugin Portal.

I had hoped that the injected project would figure out how to get the com.verificationgentleman.gradle:gradle-hdvl:0.1.0-SNAPSHOT artifact. It needs it because it depends on the local plugin and the local plugin knows how to get this artifact from mavenLocal().

Is there some way to tell it to look in mavenLocal() as well?