首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分级compileJava任务不断失败

分级compileJava任务不断失败
EN

Stack Overflow用户
提问于 2017-11-22 19:34:51
回答 2查看 3K关注 0票数 3

好吧,我已经用头撞墙了好长一段时间了,现在我甚至不知道该找什么来找到解决方案了,这是我的文件

build.gradle

代码语言:javascript
复制
    //Applying the Gradle BND Plugin for Workspace Builds
    //https://github.com/bndtools/bnd/blob/master/biz.aQute.bnd.gradle/README.md
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:${bnd_version}"
    }
}

apply plugin: 'biz.aQute.bnd.workspace'
apply plugin: 'java'

    // Repositorios, aguante Maven Central.
repositories {
    mavenCentral()

    /* Excluded, uso la dependecia de otro lado ahora.
    flatDir {
        dirs '/home/feddericokz/devTools/Equinox/Equinox-Oxygen-1a/plugins'
    }
    */
}

    // Dependencias
dependencies {
    // https://mvnrepository.com/artifact/org.osgi/org.osgi.core
    compile group: 'org.osgi', name: 'org.osgi.core', version: '6.0.0'
}

settings.gradle

代码语言:javascript
复制
/*
 * This settings file was generated by the Gradle 'init' task.
 *
 * The settings file is used to specify which projects to include in your build.
 * In a single project build this file can be empty or even removed.
 *
 * Detailed information about configuring a multi-project build in Gradle can be found
 * in the user guide at https://docs.gradle.org/4.3.1/userguide/multi_project_builds.html
 */

/*
// To declare projects as part of a multi-project build use the 'include' method
include 'shared'
include 'api'
include 'services:webservice'
*/

rootProject.name = 'bndWorkspace'

include 'com.feddericokz.helloworld'

当试图从命令行运行gradle jar时,我得到一个错误,因为编译器找不到编译类的osgi依赖项。

代码语言:javascript
复制
Task :com.feddericokz.helloworld:compileJava FAILED
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:3: error: package org.osgi.framework does not exist
import org.osgi.framework.BundleActivator;
                         ^
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:4: error: package org.osgi.framework does not exist
import org.osgi.framework.BundleContext;
                         ^
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:6: error: cannot find symbol
public class HelloWorldActivator implements BundleActivator {
                                            ^
  symbol: class BundleActivator
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:8: error: cannot find symbol
    public void start(BundleContext bundleContext) throws Exception {
                      ^
  symbol:   class BundleContext
  location: class HelloWorldActivator
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:13: error: cannot find symbol
    public void stop(BundleContext bundleContext) throws Exception {
                     ^
  symbol:   class BundleContext
  location: class HelloWorldActivator
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:7: error: method does not override or implement a method from a supertype
    @Override
    ^
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:12: error: method does not override or implement a method from a supertype
    @Override
    ^
7 errors


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':com.feddericokz.helloworld:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date

我做错什么了?

编辑:一个错误

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-22 23:42:19

如果使用Bnd工作区模型构建,则必须使用bnd.bnd Bnd指令通过每个项目的-buildpath文件配置构建路径。然后,Bnd插件将使用这些信息为java编译编写配置程序。

您的示例显示了为根级项目设置编译依赖关系,这是错误的,因为(1)您应该在项目的-buildpath文件中使用bnd.bnd,(2)它是在根项目中完成的,这对您的com.feddericokz.helloworld项目这样的任何子项目都没有意义。

因此,将build.gradle文件更改为不将'java‘插件应用于根项目,而不设置根项目的编译依赖项,并更改Bnd工作区,以便工作区(cnf)已经配置了存储库以访问所需的包(例如https://github.com/osgi/enroute.workspace/blob/4070ff6668a1ee79b9b01cfa4caab86869247e7b/cnf/ext/enroute.bnd#L22-L28 ),然后将每个项目的bnd.bnd文件设置为在-buildpath上具有所需的捆绑包。

票数 2
EN

Stack Overflow用户

发布于 2017-11-22 20:48:34

尚不清楚是否在这一行中定义了bnd_version

代码语言:javascript
复制
classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:${bnd_version}"

考虑使用以下内容添加一个gradle.properties文件:

代码语言:javascript
复制
bnd_version=3.5.0

(或按任何版本分摊)。尽我所能再现你的情况,我的例子适用于我。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47442593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档