【问题标题】:Gradle compileJava Task keeps failingGradle compileJava Task 不断失败
【发布时间】:2018-05-06 15:47:12
【问题描述】:

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

build.gradle

    //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

/*
 * 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 依赖项来编译类

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

我做错了什么?

编辑:错字

【问题讨论】:

    标签: java gradle osgi bnd


    【解决方案1】:

    不清楚bnd_version是否在这行定义:

    classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:${bnd_version}"
    

    考虑添加一个gradle.properties 文件:

    bnd_version=3.5.0
    

    (或任何合适的版本)。尽我所能重现您的情况,我的示例适用于此。

    【讨论】:

    • 我已经像你说的那样定义了它,对不起,我忘了把它添加到问题中,仍然不起作用。 :(
    【解决方案2】:

    如果您使用的是 Bnd 工作区模型构建,那么您必须使用 -buildpath Bnd 指令通过每个项目的 bnd.bnd 文件配置构建路径。然后 Bnd gradle 插件将使用该信息来编写 java 编译的配置。

    您的示例显示了为根 gradle 项目设置编译依赖项,这是错误的,因为 (1) 您应该在项目的 bnd.bnd 文件中使用 -buildpath 并且 (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 上包含所需的捆绑包。

    【讨论】:

    • 这对我来说特别棘手,因为我依赖的包已经在 -testpath 中。所以它在 Eclipse 单元测试中运行,但不在 Gradle 构建中它需要在 -buildpath 上。
    猜你喜欢
    • 2017-10-10
    • 2019-11-26
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 2017-07-29
    • 1970-01-01
    • 2020-02-25
    相关资源
    最近更新 更多