简体   繁体   中英

Using include and exclude in the jar command in gradle does not include all of the classes needed

I need to create a jar from a subset of java classes in my project. I have 3 tasks: (Copy, Compile, Jar) The copy and compile tasks work fine. They are below for reference: 1. Copy files to a directory that are needed to compile the jar. There are additional files needed in this directory that are needed in the compile but not included in the jar files.

 task copyCoreSharedFiles(type: Copy) {
        includeEmptyDirs = false
        from ('src/java/com/')
    (List of includes and excludes) 
        into  rootProject.rootDir.getAbsolutePath() + "/target" +"/coreshared"
        println 'Copied core-shared files into directory'   
    }
2. Compile the java files and stored to another directory


 task compileCoreShareJar(type: JavaCompile) {
        source = file('target/coreshared')
        destinationDir = file('target/buildtmp/core')
        classpath = configurations.compile
        println 'Compiled core-shared files into directory' 
    }

I am having trouble jarring all of the class files. The task in below.

task jarCoreShareClassFiles(type: Jar) {
    includeEmptyDirs = false
    archiveName = "core-shared-SNAPSHOT.jar"
    destinationDir = file("$rootDir/target/lib/")
    from file('target/buildtmp/core')
    include('**/com/common/*')
    include('**/com/javaserver/*')
    exclude('**/com/javaserver/dock/transaction/PrintTransaction.class')

    println 'Jar core-shared files into directory'
}

I need to include and exclude specific directories and files. When I use include('**/com/common/*') it includes the common directory files but not the subdirectory local under the common directory. It does not include the javaserver directory at all.

How do I use include and exclude in the jar command?

The * pattern does not match subdirectories. To recurse into subdirectories you can use ** .

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