通过Gradle构建emply OSGi包

时间:2016-08-05 11:19:07

标签: gradle osgi

我有build.gradle个文件:

apply plugin: "java"
apply plugin: "maven"
apply plugin: "osgi"

group = "aaa"
archivesBaseName = 'b.c.d'
version = "0.0.1-SNAPSHOT"

def packages = [
    "com.some.package1",
    "com.some.package2"
]

jar {
     manifest {
        instruction 'Bundle-Vendor', 'Some vendor'
        instruction 'Fragment-Host', 'system.bundle;extension:=framework'
        instruction 'Export-Package', packages.toString().replace("[","").replace("]","")
    }
}

我想使用jar获取空MANIFEST.MF个文件,但是:

  

Jar只能接受有效的文件或目录:/ my_directory / aaa / build / classes / main

org.gradle.api.GradleException: Could not copy MANIFEST.MF to '/my_directory/aaa/build/tmp/jar/MANIFEST.MF'.
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:79)
        at org.gradle.api.internal.file.collections.MapFileTree$FileVisitDetailsImpl.getFile(MapFileTree.java:162)
        at org.gradle.api.internal.file.collections.MapFileTree$FileVisitDetailsImpl.getSize(MapFileTree.java:222)
        at org.gradle.api.internal.file.FileTreeElementHasher.calculateHashForFileMetadata(FileTreeElementHasher.java:47)
        at org.gradle.api.internal.changedetection.state.DefaultVisitedTree.calculatePreCheckHash(DefaultVisitedTree.java:89)
        at org.gradle.api.internal.changedetection.state.VisitedTreesPreCheckHasher.calculatePreCheckHash(VisitedTreesPreCheckHasher.java:47)
        at org.gradle.api.internal.changedetection.state.AbstractFileCollectionSnapshotter$DefaultFileCollectionSnapshotPreCheck.getHash(AbstractFileCollectionSnapshotter.java:110)
        at org.gradle.api.internal.changedetection.rules.InputFilesTaskStateChanges.<init>(InputFilesTaskStateChanges.java:41)
        at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:52)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:145)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:74)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:53)
...
Caused by: java.lang.IllegalArgumentException: A Jar can only accept a valid file or directory: /my_directory/aaa/build/classes/main
        at aQute.bnd.osgi.Jar.<init>(Jar.java:58)
        at aQute.bnd.osgi.Jar.<init>(Jar.java:76)
        at aQute.bnd.osgi.Analyzer.setJar(Analyzer.java:1279)
        at org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest.setAnalyzerProperties(DefaultOsgiManifest.java:125)
        at org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest.getEffectiveManifest(DefaultOsgiManifest.java:69)
        at org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest_Decorated.getEffectiveManifest(Unknown Source)
        at org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest.getEffectiveManifest(DefaultOsgiManifest.java:35)
        at org.gradle.api.java.archives.internal.DefaultManifest.writeTo(DefaultManifest.java:220)
        at org.gradle.api.java.archives.internal.DefaultManifest.writeTo(DefaultManifest.java:214)
        at org.gradle.jvm.tasks.Jar$1$1.execute(Jar.java:77)
        at org.gradle.jvm.tasks.Jar$1$1.execute(Jar.java:64)
        at org.gradle.api.internal.file.collections.MapFileTree$FileVisitDetailsImpl.copyTo(MapFileTree.java:174)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:93)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:74)
        ... 65 more

如果我在/my_directory/aaa/src/main/java/中创建空类,它可以正常工作。我也可以在没有jar插件的情况下制作此osgi,但这将是一个更好的解决方案。

0 个答案:

没有答案