简体   繁体   中英

How to exclude configuration files from jar generated by gradle

I have two projects:

  • 1) common
  • 2) app

app is a project that depends on common.

The project structure is:

project
    common 
         conf
         src
            java
            test
    app 
         conf
         src
            java 
            test

So in terms of build.gradle

common:

dependencies {
    ....
}
sourceSets {
    main {
        java {
            srcDir 'src/java'
            exclude 'conf'
        }
        resources {
            srcDir 'conf'
        }
    }

    test {
        java {
            srcDir 'src/test'
        }
    }
}

app:

dependencies {
    compile project(':common')
    ....
}
sourceSets {
    main {
        java {
            srcDir 'src/java'
            exclude 'conf'
        }
        resources {
            srcDir 'conf'
        }
    }

    test {
        java {
            srcDir 'src/test'
        }
    }
}

However, when I check the common.jar generated in build folder when I run test cases of app . I can see that common.jar includes *.xml files of conf.

I also tried to add the following to common build.gradle:

jar { 
    exclude('conf/**') 
} 

but doesn't seem to work.

Is there a way to exclude conf/*xml from common.jar only when I run test cases of app ?

In your build.gradle file, you can add the exclude command followed by the files that you want to exclude

jar {     
   exclude('your file name')     
}

Also if you want to exclude more than one file

jar { 
    exclude('file1', 'file2')
  }

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