Hello There!
When you wanted to build a jar file from your code, you accidentally facing an error such like below :
Entry META-INF/LICENSE.txt is a duplicate but no duplicate handling strategy has been set. Please refer to…. That is I because you haven’t set any duplicates Strategy in your build.gradle file.
You need to add a 1 line code like below.
duplicatesStrategy(DuplicatesStrategy.EXCLUDE);So, the before code is :
jar {
manifest {
attributes 'Main-Class': 'your.main.class.Class'
}
from {
configurations.implementation.setCanBeResolved(true)
configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
this is after you add the code.
jar {
manifest {
attributes 'Main-Class': 'your.main.class.Class’
}
from {
configurations.implementation.setCanBeResolved(true)
configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
That will solved your problem though.
DuplicatesStrategy is a constant that has a different function.
| EXCLUDE | Do not allow duplicates by ignoring subsequent items to be created at the same path. |
| FAIL | Throw a DuplicateFileCopyingException when subsequent items are to be created at the same path. |
| INCLUDE | Do not attempt to prevent duplicates. |
| INHERIT | The default strategy, which is to inherit the strategy from the parent copy spec, if any, or INCLUDE if the copy spec has no parent. |
| WARN | Do not attempt to prevent duplicates, but log a warning message when multiple items are to be created at the same path. |
More information please check this url.




Leave a Reply