3

我正在尝试创建一个类似于此结构的 Gradle 多项目

ouat-services
  - ouat-contract
  - ouat-servicesImpl (web project)

我遵循了 eclipse 示例并将我的 ouat-services settings.gradle 定义为

include "ouat-contract", "ouat-servicesImpl"

在我的 ouat-servicesImpl build-gradle 我定义

dependencies {
  compile project(':ouat-contract')
}

当我尝试在 ouat-servicesImpl 中应用 war 插件时,我的问题就开始了,我在 eclipse 问题视图中收到以下消息:

Invalid classpath publish/ export dependency /ouat-contract. Project entries not supported

我的 ouat 服务 build.gradle

configure(subprojects) {

  apply plugin: 'com.github.ben-manes.versions'
  apply plugin: 'eclipse'
  apply plugin: 'java'

  version = '1.0'

  sourceCompatibility = 1.8
  targetCompatibility = 1.8

  def defaultEncoding = 'UTF-8'
  [compileJava, compileTestJava]*.options*.encoding = defaultEncoding

  repositories {

    jcenter()
    mavenLocal()
    mavenCentral()
  }

  jar {
    manifest.attributes provider: 'Company'
  }
}

configure(project(':ouat-servicesImpl')) {

  apply plugin: 'checkstyle'
  apply plugin: 'eclipse-wtp'
  apply plugin: 'findbugs'
  apply plugin: 'jacoco'
  //apply plugin: 'jetty'
  apply plugin: 'pmd'
  apply plugin: 'war'
}

buildscript {

  repositories {

    jcenter()
    mavenCentral()
    mavenLocal()
  }

  dependencies {
    classpath 'com.github.ben-manes:gradle-versions-plugin:0.10.1'
  }
}

我的 ouat-servicesImpl 构建 gradle 更改为:

dependencies {

  compile project(':ouat-contract')

  cxfArtifacts.each { artifact ->
    compile "org.apache.cxf:$artifact:$cxfVersion"
  }

  springArtifacts.each { artifact ->
    compile "org.springframework:$artifact:$springVersion"
  }

  testCompile "org.testng:testng:$testNGVersion"
  testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
  testCompile "org.springframework:spring-test:$springVersion"

  //WAR PLUGIN
  providedCompile "javax.servlet:javax.servlet-api:$servletAPIVersion"
  runtime "javax.servlet:jstl:$jstlVersion"
}

这是eclipse插件问题还是我做错了什么?

4

4 回答 4

11

这是我发现的神奇步骤,可以让它在不手动弄乱项目设置的情况下工作。

  1. 运行命令:gradle cleanEclipse eclipse

    • 由于这个命令,Eclipse 忘记了该项目应该具有 gradle 特性。
  2. 通过执行配置 -> 转换为 Gradle 项目,将 gradle 自然添加回项目。

    • 由于此命令,错误再次出现。
    • 如果出现不兼容的插件 java 版本错误,则只需删除 .settings 目录并刷新。
  3. 运行命令:gradle cleanEclipseClasspath eclipseClasspath

    • 这最后一步应该修复它,直到下一次。
于 2015-09-02T17:16:12.067 回答
6

就我而言,这是由于混合了“多面”和非多面项目。有错误的项目已转换为分面形式,而他们所抱怨的项目却没有。您可以通过使用eclipse-wtp插件将项目配置为分面,方法是将其添加到您的 ouat-contract gradle 文件中:

eclipse{
    wtp{
        facet{}
    }
}

这将在使用 java 和 war 插件时为 Java 和实用程序模块添加构面(有关默认值的更多信息,请参阅EclipseWTPFacet文档,如果您不使用 war 插件,请手动添加构面)。实用程序模块部分是避免错误的关键。

请注意,如果您需要执行其他操作,例如指定特定的 Apache Tomcat 运行时或类似内容,您还可以在此块中直接访问构面文件以执行手动 XML 操作

进行此更改后,您可以使用 Eclipse 执行 Gradle -> Refresh All on ouat-contract 在您的工作区中 - 一旦我这样做了,错误就消失了

于 2016-06-16T17:19:14.930 回答
0

我很久以前也遇到过这个问题。这似乎是与“Gradle IDE Pack”中包含的 Eclipse 插件相关的问题(因为它可以在命令行中正常工作)。我的设置可能比你的复杂得多(我将一个顶级 gradle 项目中的模块包含到另一个顶级 gradle 项目中),但要克服这个特定错误

Invalid classpath publish/ export dependency /my-project. Project entries not supported

...如果缺少某些特定的 gradle 属性,我排除了项目依赖项:

if(project.hasProperty("myProjectRefAddedFromIDE")) {
    println "NB! Build script started with property 'myProjectRefAddedFromIDE' - expecting that this project in IDE is configured to add the direct reference to my-project"
} else {
    compile project(':my-project')
}

并且要仅从 IDE 添加属性“myProjectRefAddedFromIDE”,我已将 eclipse 插件配置如下:Window -> Preferences -> Gradle -> Arguments -> Program arguments -> Use: ´-PmyProjectRefAddedFromIDE´

只是一个警告:这可能对您有用,但您的设置可能存在其他问题,至于简单的多模块项目(不包括来自另一个多模块项目的模块)我不必使用这种解决方法。

于 2015-06-04T12:35:26.643 回答
0

这对我来说可以从 JRE 系统库中删除重复的 jar 文件。步骤 右键单击​​ Project 并转到 Build Path->configure build path->Libraries。删除不在类路径中或在 Maven 依赖项中重复的 jar。

于 2020-08-07T12:38:48.037 回答