简体   繁体   中英

Gradle Jar - Include dependencies' classes

I'm working on a server application and using gradle for this. If i run "bundle", gradle creates a jar file which includes all compiled java classes of my project. But, obviously, you cannot run this jar because of the missing dependencies.

I currently these own task:

task bundleJar(type: Jar) {
    manifest {
        attributes 'Main-Class': 'your.own.start.main.class'
    }
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

But this includes "ALL" dependencies classes. It is possible to integrate only classes which are needed by my application? Are they any problems with reflections?

Another thing I thought about. Some libraries disallow to ship them in another application. So I only provide the source code to my users. They download it and execute the gradle task. This should be ok, shouldn't it? Is it better to bunld eeverything in one jar, or is it possible to create a seperate folder for needed classes?

Thx:)

In your example, you do configurations.compile.collect so you will zip everything from the compile scope. you could change that with the class declared from your runtime scope ( configurations.runtime.collect ). sure it would mean that those classes have already been downloaded when you are doing the build.

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