I am currently trying to migrate a Maven
project to Gradle
In my Maven
version I have the dependency versions all listed out like this in my parent pom:
<properties> <spring.version>4.2.3.RELEASE</spring.version> <spring.boot.version>1.3.3.RELEASE</spring.boot.version> ... </properties>
And then I can define a dependency like this in any of my sub-modules:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency>
I am attempting to do the same thing on Gradle
, because some of my modules share dependency versions like this, and I wouldn't like to modify more then one place if I want to upgrade Spring or do a similar operation.
The closest I have gotten to it is this:
dependencies { ext.springVersion = '4.2.3.RELEASE' compile "org.springframework:spring-jdbc:$springVersion" }
Yet that still doesn't work. What is the recommended way to achieve this in Gradle? Or does Gradle treat this differently? Perhaps my mind is still too much on Maven to see another solution.
Please keep in mind that that attempt on Gradle isn't exactly what I want yet. I would like to be able to define the dependencies in a separate file, not directly on the file that will use it.
Gradle build script defines a process to build projects; each project contains some dependencies and some publications. Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path.
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.
Below configuration in build.gradle
file worked for me with gradle version 4.5
, posting it here for future reference -
ext { springVersion = '5.0.3.RELEASE' } dependencies { compile "org.springframework:spring-context:$springVersion" }
Use Double Quotes it worked for me.
buildscript { ext { springBootVersion = '2.0.4.RELEASE' hazelCastVersion = '3.10.4' } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } dependencies { compile('org.springframework.cloud:spring-cloud-starter-config') compile "com.hazelcast:hazelcast-spring:${hazelCastVersion}" compile group: 'com.hazelcast', name: 'hazelcast', version: "${hazelCastVersion}" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With