简体   繁体   中英

Gradle: JDBC driver not compiled into JAR

I have a module build.gradle file that looks like this:

apply plugin: 'java'

sourceCompatibility = 1.5
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'mysql:mysql-connector-java:5.1.6'
}

I also have an artefact set up like this:

截图

When I build this artifact, my classes are included but MySQL driver is not. When executed, MySQL driver class is not found. How do I build so that my JAR artifact (used as a library) ccontains MySQL JDBC driver?

Configuring this in Gradle and IntelliJ is two different things. The most direct way to create a fat Jar in Gradle is:

jar {
    from { configurations.runtime.collect { it.directory ? it : zipTree(it) } }
}

PS: Merging Jars can cause problems. In most cases it should not be done, in particular for a library.

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