4

I am trying to create a fat jar using gradle and I am using following dependency

implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000')
implementation 'com.amazonaws:aws-java-sdk-core'
implementation("software.amazon.msk:aws-msk-iam-auth:1.1.1")
implementation("org.apache.kafka:kafka-clients:3.0.0")
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'    
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

But I am getting this error

Entry META-INF/LICENSE.txt is a duplicate but no duplicate handling strategy has been set

Any Suggestions?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Tony Dubey
  • 41
  • 2

1 Answers1

0

I got this answer from here and it worked, just make sure to add onto your fatJar task the line "duplicatesStrategy = DuplicatesStrategy.EXCLUDE" at the start and the error should be managed. After finding the first, any subsequent "META-INF/LISCENSE.txt" will just be ignored. Other options are DuplicatesStrategy.INCLUDE if you do want them and even more are explained here but briefly include:

  • FAIL-errors out
  • WARN-throws a warning on build but will include duplicates
  • INHERET-inherits any parent CopySpec's function or INCLUDE if one doesn't exist
task fatJar(type: Jar) { 
    manifest.from jar.manifest 
    classifier = 'all' 
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE 
    from { 
        configurations.runtimeClasspath.collect { 
            it.isDirectory() ? it : zipTree(it) 
        } 
    } { 
    exclude "META-INF/*.SF" 
    exclude "META-INF/*.DSA" 
    exclude "META-INF/*.RSA" 
    } 
    with jar 
} 
jar { 
    manifest { 
        attributes 'Main-Class': 'YOUR_MAIN_CLASS' 
    } 
}
clivet268
  • 43
  • 1
  • 5
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33328046) – Ragnar Dec 08 '22 at 06:10