28

I want to exclude AMAuthN.properties from the built jar. This file keeps showing up in the root folder of the compiled jar. The file is located at AMAuthN\src\main\resources\AMAuthN.properties relative to the project folder root. Thanks!

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'
}
Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27
Wes
  • 1,183
  • 3
  • 23
  • 51

1 Answers1

36

You can try something like this, which i know works on my end. In your build.gradle under the JAR definition add your exclude. Ex:

jar {     
   exclude('your thing')     
}
Opal
  • 81,889
  • 28
  • 189
  • 210
SomeStudent
  • 2,856
  • 1
  • 22
  • 36
  • 8
    for excluding more than one thing use: `jar { exclude('thing1', 'thing2')}` – Camilo Silva Apr 25 '17 at 21:40
  • 3
    what path we should add? – user666 Apr 08 '19 at 07:06
  • Is there no way to put properties files in a separate directory from src and then instruct Gradle to use an updated classpath which includes the property files when running tests? – Ryan Oct 30 '19 at 18:08
  • I have not been able to get this to work. I first tried with no path and then with a fully-qualified path, but the file I'm trying to exclude still appears in the JAR file. – Greg Brown Mar 26 '23 at 16:31