我想过滤掉Import-Package
指令的条目,因为它是一个太阳原生包。
目前生成的Manifest读取
Import-Package: javax.net.ssl,javax.security.auth.kerberos,org.jivesof
tware.smack;version="[4.1,5)",org.jivesoftware.smack.initializer;vers
ion="[4.1,5)",org.jivesoftware.smack.util.stringencoder;version="[4.1
,5)",sun.security.util
但是,我想删除sun.security.util
,以便它变为
Import-Package: javax.net.ssl,javax.security.auth.kerberos,org.jivesof
tware.smack;version="[4.1,5)",org.jivesoftware.smack.initializer;vers
ion="[4.1,5)",org.jivesoftware.smack.util.stringencoder;version="[4.1
,5)"
我认为应该可以使用像
这样的东西afterEvaluate { project ->
def importPackages = ((OsgiManifest) project.jar.manifest).instructionValue('Import-Packages')
def filteredImportPackages = importPackages.findAll { it != 'sun.security.util' }
((OsgiManifest) project.jar.manifest).instructionReplace('Import-Packages', filteredImportPackages)
}
但是这会导致ClassCastException:
Cannot cast object 'org.gradle.api.java.archives.internal.DefaultManifest@136bec49' with class 'org.gradle.api.java.archives.internal.DefaultManifest' to class 'org.gradle.api.plugins.osgi.OsgiManifest'
如何在gradle配置之后操作(Osgi)清单?
答案 0 :(得分:4)
您应该只使用这样的bnd说明删除sun.security.util
包:
jar {
manifest { // the manifest of the default jar is of type OsgiManifest
instruction 'Import-Package', '!sun.security.*, *'
}
}