VTUFORUM
Adding dependencies to the Java project using Gralde - Printable Version

+- VTUFORUM (http://www.vtuforum.com)
+-- Forum: KnowledgeBase (/Forum-KnowledgeBase)
+--- Forum: Concepts and Tutorials (/Forum-Concepts-and-Tutorials)
+--- Thread: Adding dependencies to the Java project using Gralde (/Thread-Adding-dependencies-to-the-Java-project-using-Gralde)



Adding dependencies to the Java project using Gralde - Sandeep - 04-09-2015 10:45 PM

Hello this tutorial is about adding depencies or external .jar file to the java project and we are going to continue the previous Gradle project which we can find here

Here we are going to add a library from the apache maven, if you look at the java file written you will find a extra line at the import

Quote:import org.apache.commons.lang3.StringUtils;

and using the function from this import i.e StringUtils.swapCase()

if you want to make this things we need to make some changes in build.gradle. Gradle came with the default mevan repository which we have as mavenCentral() which gets downloaded or you can use mavenLocal() and bring this repository by linking dependency of it and we have to put this dependency generated jar also. So here is how we do it

Quote:repositories{
mavenCentral()
}
apply plugin: "java"
configurations{
myConfig
}
dependencies{
compile "org.apache.commons:commons-lang3:3.3.2"
myConfig "org.apache.commons:commons-lang3:3.3.2"
}
sourceSets{
main.java.srcDir "src/main"
test.java.srcDir "src/test"
}
jar{
from configurations.myConfig.collect { zipTree it }
manifest.attributes "Main-class":"com.sandeep.gradleTutorial.Main"
}


So now run the project using follwing statement

$ gradle clean
$ gradle build
$ java -jar build/libs/gradleTutorials.jar

The code is attached with this post, download and try to understand it

Happy coding Big Grin