我是Gradle的新手,请帮助我理解以下内容。我正在尝试通过Intellij Idea + Gradle构建一个OSGI web应用。我发现Gradle有OSGI插件,描述如下:https://docs.gradle.org/current/userguide/osgi_plugin.html
但我不知道如何添加依赖,例如,org.apache.felix.dependencymanager,这是OSGI包。因此,我在编译时需要这个jar,而在生成的jar中不需要它。我想,我需要一些类似于maven 'provided‘作用域的东西,或者类似的东西。
附言:有人明白Gradle文档中“待定”是什么意思吗?这是否意味着它必须在未来实现,或者已经实现了某种机制,但文档中尚未对其进行描述?
发布于 2016-05-12 03:12:06
请看看我写的插件,osgi-run,它的设计目的是在不使用任何外部工具的情况下非常容易地使用OSGi (尽管osgi-run可以为你生成一个清单文件,你可以从你的集成开发环境中指向它来获得集成开发环境的OSGi支持-这就是我使用IntelliJ做的),只是Gradle。
使用osgi-run,您只需向任何您想要的项目中添加一个依赖项...在编译时,它是否应该由环境提供并不重要,这是一个部署时的问题。
例如,添加到您的build.gradle文件:
apply plugin: 'osgi' // or other OSGi plugin if you prefer
repositories {
mavenCentral() // add repos to get your dependencies from
}
dependencies {
compile "org.apache.felix:org.apache.felix.dependencymanager:4.3.0"
}注意: osgi插件只是将jar转换为捆绑包所必需的。osgi-run不会这样做。
如果您有任何应该存在于OSGi环境中但不存在于编译类路径中的运行时依赖项,请执行以下操作:
dependencies {
...
osgiRuntime 'org.apache.felix:org.apache.felix.configadmin:1.8.8'
}现在编写一些代码,一旦您准备好运行一个包含您的东西的OSGi容器,就可以向build.gradle文件添加以下行:
// this should be the first line
plugins {
id "com.athaydes.osgi-run" version "1.4.3"
}
...
// deployment to OSGi container config
runOsgi {
// which bundles do you want to add?
// transitive deps will be automatically added
bundles += project
// do not deploy jars matching these regexes (not needed, this is the default)
excludedBundles = ['org\\.osgi\\..*']
// make the manifest visible to the IDE for OSGi support
copyManifestTo file( 'auto-generated/MANIFEST.MF' )
}运行:
gradle createOsgiRuntime并在build/osgi目录中找到可以运行的完整OSGi环境。
使用以下命令运行它:
build/osgi/run.sh # or run.bat in Windows您甚至可以在构建过程中运行它:
gradle runOsgi发布于 2016-05-11 10:23:00
因此,您可能希望进行自己的provided配置。
configurations {
// define new scope
provided
}
sourceSets {
// add the configurations to the compile classpath but not runtime
main.compileClasspath += configurations.provided
// be sure to add the provided configs to your tests too if needed
test.compileClasspath += configurations.provided
}
dependencies {
// declare your provided dependencies
provided 'org.apache.felix:org.apache.felix.dependencymanager:4.3.0'
}此外,上面关于直接使用bndtool而不是gradle提供的osgi插件的建议也很好。gradle插件有很多不足之处,而且实际上只是bndtool的一个包装器。此外,gradle团队已经宣布,他们没有带宽或专业知识来修复osgi插件1。
https://stackoverflow.com/questions/37145375
复制相似问题