How to get Gradle Spring dependency plugin to work?
Solution 1
What you need to do is to define a dependency for build.gradle
itself that has the plugin you're looking for. It may be e.g.:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
}
}
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
Solution 2
Take a look at the official user guide, section called "external dependencies". According to it:
If your build script needs to use external libraries, you can add them to the script's classpath in the build script itself. You do this using the buildscript() method, passing in a closure which declares the build script classpath.
In your case,a plugin is an external dependency, and you have to provide buildscript section for all the project, which need to apply this plugin.
Related videos on Youtube
user447607
Updated on October 10, 2022Comments
-
user447607 over 1 year
Because I'm such a newb at this, the problem is context. Their example doesn't match my build. I've installed the jar locally so it should definitely be available.
My project looks like:
allprojects { apply plugin: 'maven' apply plugin: "io.spring.dependency-management" group = 'com.wnp' version = '6.5.0-SNAPSHOT' } subprojects { apply plugin: 'java' sourceCompatibility = System.getProperty("java.version") targetCompatibility = System.getProperty("java.version") repositories { mavenLocal() mavenCentral() jcenter() } dependencyManagement { imports { mavenBom 'org.springframework.ws:spring-ws:2.1.4.RELEASE' mavenBom 'org.jboss.as:jboss-as-jms-client-bom:7.5.0.Final-redhat-21' } dependencies { dependency "antlr:antlr:2.7.7" } } apply plugin: "io.spring.dependency-management"
Their project looks like:
buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE" } } apply plugin: "io.spring.dependency-management"
What I'm getting from the system is :
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'io.spring.dependency-management' not found.
Clues? What does "buildscript" represent? Is that a task? I've tried putting the "dependencies" section just about everywhere. Same goes with the "apply plugin:" line. Is my dependencyManagement section in the right place? One of the things I keep seeing is "dependencies cannot be applied to closure" which is pretty unhelpful as far as error messages go.
-
user447607 over 8 yearsIs that what buildscript is for?
-
Opal over 8 yearsIf I weren't to write 15 characters I would just wrote: Yes. So, yes.
-
user447607 over 8 yearsGood to know. It seems to work now. Thanks for info regarding buildscript. Not found anywhere else. Probably assuming I know Groovy but like many, Gradle is my reason for learning Groovy as well so I get both barrels. :-/
-
Opal over 8 yearsPlease have a look here. The example uses the plugin you need.
-
user447607 over 8 yearsFor the record, I had been there. The dissimilarity between my build and theirs was the reason for the confusion.
-
iUbaid about 5 yearsAfter Implementing the above scenario :
Could not find org.grails.plugins:hibernate5:6.0.2. Searched in the following locations: - https://repo.maven.apache.org/maven2/org/grails/plugins/hibernate5/6.0.2/hibernate5-6.0.2.pom - https://repo.maven.apache.org/maven2/org/grails/plugins/hibernate5/6.0.2/hibernate5-6.0.2.jar - https://plugins.gradle.org/m2/org/grails/plugins/hibernate5/6.0.2/hibernate5-6.0.2.pom - https://plugins.gradle.org/m2/org/grails/plugins/hibernate5/6.0.2/hibernate5-6.0.2.jar Required by: project :