diff --git a/jhdf/build.gradle b/jhdf/build.gradle index 0a91a19f..90f11bf2 100644 --- a/jhdf/build.gradle +++ b/jhdf/build.gradle @@ -105,7 +105,7 @@ jar { 'Bundle-Vendor': 'James Mudd', 'Bundle-Version': project.version, 'Export-Package': 'io.jhdf,io.jhdf.*,io.jhdf.api,io.jhdf.api.*', - 'Require-Bundle': 'slf4j.api;bundle-version="1.7.36",org.apache.commons.lang3;bundle-version="3.17.0",com.ning.compress-lzf;bundle-version="1.1.2",lz4-java;bundle-version="1.8.0"', + 'Require-Bundle': buildRequireBundleHeader(), // Build data 'Build-JDK': System.getProperty('java.vendor') + ' ' + System.getProperty('java.version'), 'Build-OS': System.getProperty('os.name') + ' ' + System.getProperty('os.version'), @@ -198,6 +198,9 @@ signing { import com.github.spotbugs.snom.Confidence import com.github.spotbugs.snom.Effort + +import java.util.stream.Collectors + spotbugs { ignoreFailures = true // Allow build to continue with errors effort = Effort.valueOf('MAX') @@ -222,3 +225,28 @@ sonarqube { property "sonar.java.checkstyle.reportPaths", "build/reports/checkstyle/main.xml,build/reports/checkstyle/test.xml" } } + +String buildRequireBundleHeader() { + def runtimeDependencies = configurations.runtimeClasspath.getAllDependencies() + def bundleToModule = [ + "slf4j.api": "org.slf4j:slf4j-api", + "org.apache.commons.lang3": "org.apache.commons:commons-lang3", + "com.ning.compress-lzf": "com.ning:compress-lzf", + "lz4-java": "org.lz4:lz4-java" + ] + + def moduleToVersion = runtimeDependencies.collectEntries { + [it.module.toString(), it.version] + } + + // Check here to catch when dependencies are added/removed + if(!bundleToModule.values().containsAll(moduleToVersion.keySet())) { + throw new IllegalStateException("Runtime dependencies not mapped for OSGi") + } + + def header = bundleToModule.entrySet().stream() + .map {"${it.key};bundle-version=\"${moduleToVersion.get(it.value)}\"" } + .collect(Collectors.joining(",")) + + return header +}