Configuring task causes dependency to not be found anymore


(ThomasE) #1

project1

  • group: “com.group.my
  • name: “project1”
  • current version: “0.0.8-SNAPSHOT”
  • last version released to archive server: “0.0.7”
  • build.gradle contains
apply plugin: 'project2.plugin'
buildscript {
    repositories {
        maven {
            url "https://my-archive-sever.local/repository/maven-public/"
        }
        mavenCentral()
    }
    dependencies {
        classpath group: "com.group.my", name: "project2", version: "0.0.1"
    }
}

project2

  • group: “com.group.my
  • name: “project2”
  • current version: “0.0.2-SNAPSHOT”
  • last version released to archive server: “0.0.1”
  • has dependency
    • compile group: “com.group.my”, name: “project1”, version: “0.0.7”
    • resolved via archive server in normal “repositories” block
  • builds a gradle plugin which provides
    • a build task “doSomething”
    • settings for task “doSomething” via “doSomethingSettings”
  • correctness of plugin is verified by using it in project3 in the exact same way as in project1

When doing EXACTLY as above, I can build project1 successfully. However, when I try to configure the task “doSomething” with a “doSomethingSettings” block in project1’s build.gradle file, all of a sudden the dependency resolution fails.

This is what I try to insert into project1’s build.gradle file:

integrityCheckSettings {
    def ncl = new GroovyClassLoader()
    ncl.addClasspath("${sourceSets.main.output.classesDir}")
    configurations.compile.each { ncl.addClasspath(it.path) }
   ...
}

And this is the error I get when running gradle buildEnvironment for project1:

* What went wrong:
A problem occurred evaluating root project 'project1'.
> Could not resolve all dependencies for configuration ':compile'.
> Cannot resolve external dependency com.google.code.gson:gson:2.7 because no repositories are defined.
 Required by:
     com.group.my:project1:0.0.8-SNAPSHOT
> Cannot resolve external dependency org.apache.derby:derby:10.12.1.1 because no repositories are defined.
 Required by:
     com.group.my:project1:0.0.8-SNAPSHOT
> Cannot resolve external dependency com.sparkjava:spark-core:2.6.0 because no repositories are defined.
 Required by:
     com.group.my:project1:0.0.8-SNAPSHOT

The problem disappears if I comment out this line:

configurations.compile.each { ncl.addClasspath(it.path) }

Anyone care to point out what I’m doing wrong here ?