Gradle - 排除文件不被打包进jar文件

28

我希望能够从构建的 JAR 中排除AMAuthN.properties文件。该文件一直出现在编译后 JAR 的根目录中。该文件位于项目文件夹根目录下的AMAuthN\src\main\resources\AMAuthN.properties位置。谢谢!

apply plugin: 'java'
apply plugin: 'eclipse'

version = '1.0'
sourceCompatibility = 1.6
targetCompatibility = 1.6

test {
    testLogging {
        showStandardStreams = true
    }
}

// Create a single Jar with all dependencies
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',  
            'Implementation-Version': version,
            'Main-Class': 'com.axa.openam'
    }

    baseName = project.name

    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it) 
        }
    }
}

// Get dependencies from Maven central repository
repositories {
    mavenCentral()
}

// Project dependencies
dependencies {
    compile 'com.google.code.gson:gson:2.5'
    testCompile 'junit:junit:4.12'
}
1个回答

36
您可以尝试这样做,我知道它在我的端上有效。在您的build.gradle文件中,在JAR定义下添加exclude即可。例如:
jar {     
   exclude('your thing')     
}

8
排除超过一个东西时使用:jar { exclude('thing1', 'thing2')} - Camilo Silva
3
我们应该添加哪个路径? - user666
有没有办法将属性文件放在与 src 不同的单独目录中,然后指示 Gradle 使用更新的类路径,在运行测试时包括属性文件? - Ryan
我一直无法使其正常工作。我首先尝试了没有路径,然后又尝试了完全限定的路径,但我想要排除的文件仍然出现在JAR文件中。 - Greg Brown
好的,谢谢你告诉我。@GregBrown - undefined
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接