Apply plugin configuration in init.gradle script

Hi,

I want to install some packages locally for all my projects, e.g. dependency-analyse. But I need to actually configure the plugin - also in the init schript.

initscript {
  repositories {
    repositories {
      jcenter()
    }
    dependencies {
      classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
    }
  }
}
allprojects {
  apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
}

This init script works fine and applys the plugin, but unfortunately the default setting is that the plugin fails the build. I would like to just log a warn.
For that I need to add configs:

analyzeClassesDependencies {
  justWarn = true
}

analyzeTestClassesDependencies {
  justWarn = true
}

but when I try to add it in the init.gradle file:

initscript {
  repositories {
    repositories {
      jcenter()
    }
    dependencies {
      classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
    }
}
allprojects {
  apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
  analyzeClassesDependencies {
    justWarn = true
  }

  analyzeTestClassesDependencies {
    justWarn = true
  }
}

I get an error:

FAILURE: Build failed with an exception.

* Where:
Initialization script '/Users/<my-user>/.gradle/init.gradle' line: 13

* What went wrong:
Could not find method analyzeClassesDependencies() for arguments [init_2y9p9if69e8553k9fsvzz4a28$_run_closure1$_closure2@3e17c37a] on root project 'my-project' of type org.gradle.api.Project.

Anybody an idea how I can apply plugin configuration?

According to that plugin’s README, it looks like you need to have apply plugin: java before applying that plugin.

Try this and please let us know if it works for you — or not:

initscript {
    repositories {
      jcenter()
    }
    dependencies {
      classpath "ca.cutterslade.gradle:gradle-dependency-analyze:1.3.0"
    }
}

allprojects {
    apply plugin: 'java' 
    apply plugin: ca.cutterslade.gradle.analyze.AnalyzeDependenciesPlugin
	
    analyzeClassesDependencies {
        // Set to true to print a warning rather than fail the build if the dependency analysis fails
        justWarn = true
    }

    analyzeTestClassesDependencies {
        // Set to true to print a warning rather than fail the build if the dependency analysis fails
        justWarn = true
    }
}
...

Just an aside: Is there a particular reason why you need the nested repositories{ repositories {...} } blocks?

Hi :slight_smile: What did you end up doing to get your script to work?

I’m planning on implementing a plugin that will need to do something similar to that one you’re using. I’m curious to know whether any of his ideas are worth borrowing. Or maybe I can learn from his mistakes :wink:

Hi, thanks for the help. the application of the java plugin did the trick :slight_smile:

I also removed the one repository wrapping, I have no idea where that comes from :wink:

1 Like