简体   繁体   中英

Building a Fat jar with local dependencies Gradle

I have a build.gradle file as follows

buildscript {
    repositories { jcenter() }
}

dependencies {
    compile 'io.dropwizard:dropwizard-core:0.8.2'
    compile 'io.dropwizard:dropwizard-testing:0.8.2'
}

When I run gradle build it downloads the dropwizard dependencies from maven repository and builds a fat jar. Every time I pull the code in a new development environment it fetches from the maven central repo. But some of the development machines do not have internet access, to build in these machines, I thought if I could create a folder called libs in the source code root folder and use this folder as to load the jar files, like

repositories {
   flatDir {
       dirs 'libs'
   }
}

Is it possible to do? Where to find the downloaded jars from maven central in my local machine, so that I can copy them into the libs folder (dropwizard 0.8.2 jar)

Yes, it's possible. Create the following task:

task copyLibs(type: Copy) {
   from configurations.compile
   into 'libs'
}

After running this task you'll have a folder libs with all the dependencies (you might need a broader range than just compile - so align the task). You need to check this folder to SCM and commit it.

Of course mind the fact that it won't automatically update the dependencies if you eg change the version - you need to do it manually or maybe write a plugin that does all the things you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM