license-maven-plugin icon indicating copy to clipboard operation
license-maven-plugin copied to clipboard

FileAlreadyExists exception when organizeLicensesByDependencies is true and a license is cached

Open srdo opened this issue 5 years ago • 2 comments

Trying to download licenses with organizeLicensesByDependencies set to true.

[WARNING] Unable to retrieve license from URL 'http://www.apache.org/licenses/LICENSE-2.0.txt' for dependency 'org.apache.commons:commons-lang3': /mnt/c/Users/Esran/Documents/NetbeansProjects/storm/target/generated-resources/licenses/org.apache.commons.commons-lang3_the_apache_software_license,_version_2.0
[DEBUG] 
java.nio.file.FileAlreadyExistsException: /mnt/c/Users/Esran/Documents/NetbeansProjects/storm/target/generated-resources/licenses/org.apache.commons.commons-lang3_the_apache_software_license,_version_2.0
    at sun.nio.fs.UnixCopyFile.copy (UnixCopyFile.java:551)
    at sun.nio.fs.UnixFileSystemProvider.copy (UnixFileSystemProvider.java:253)
    at java.nio.file.Files.copy (Files.java:1274)
    at org.codehaus.mojo.license.AbstractDownloadLicensesMojo.downloadLicenses (AbstractDownloadLicensesMojo.java:1082)

The broken code seems to be https://github.com/mojohaus/license-maven-plugin/blob/license-maven-plugin-1.19/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java#L1082

I'm not sure what that code is supposed to do, but if the target file is supposed to be overwritten, the copy call should set CopyOption.REPLACE_EXISTING.

srdo avatar Mar 26 '19 18:03 srdo

Thanks for the report.

Yes, I think adding CopyOption.REPLACE_EXISTING could fix it.

Looks like we have just two integration tests with organizeLicensesByDependencies=true which apparently do not cover this situation. Please add a test in https://github.com/mojohaus/license-maven-plugin/tree/master/src/it that reproduces your scenario and make sure it fails before and passes after applying your fix.

ppalaga avatar Mar 27 '19 08:03 ppalaga

This happens if a dependency with the same ga appears several times in the dependency tree with different versions. Since the current filename mapping doesn't contain the version, the second execution fails.

Vlatombe avatar Dec 13 '19 13:12 Vlatombe