diff --git a/biz.aQute.bnd.gradle/src/aQute/bnd/gradle/BndUtils.groovy b/biz.aQute.bnd.gradle/src/aQute/bnd/gradle/BndUtils.groovy index f41b82ecbd..cf3ad6c965 100644 --- a/biz.aQute.bnd.gradle/src/aQute/bnd/gradle/BndUtils.groovy +++ b/biz.aQute.bnd.gradle/src/aQute/bnd/gradle/BndUtils.groovy @@ -65,7 +65,15 @@ class BndUtils { public static void jarLibraryElements(Project project, String configurationName) { if (IS_GRADLE_COMPATIBLE_5_6) { - project.configurations[configurationName].attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.class, LibraryElements.JAR)) + def attributes = project.configurations[configurationName].attributes + if (attributes.getAttribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE)?.name != LibraryElements.JAR) { + try { + attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements.class, LibraryElements.JAR)) + project.logger.info 'Set {}:{} configuration attribute {} to {}', project.path, configurationName, LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, attributes.getAttribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE) + } catch (IllegalArgumentException e) { + project.logger.info 'Unable to set {}:{} configuration attribute {} to {}', project.path, configurationName, LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, LibraryElements.JAR, e + } + } } } }