我们设置了2个项目,1个主项目和1个子项目,它们是Java项目。 它们都在同一个目录下。
以下是目录结构的样子:
./dev
./Project_A
build.gradle
settings.gradle
./Project_B
build.gradle
Project_A包括Project_B。
Project_A settings.gradle看起来像:
includeFlat 'Project_B'
Project_A build.gradle包含:
compile project(':Project_B')
问题 从命令行编译时,Project_A错过了Project_B中的类( gradlew clean build )。 看起来Project_B不属于Project-A的类路径。
这是 gradlew clean build 的一部分(在输出中)在Project_A目录中运行(之后全部"包project_b.xy缺失"和"找不到符号"(来自Project_B):
:clean
:Project_B:clean
:Project_B:compileJava
:Project_B:processResources
:Project_B:classes
:Project_B:jar UP-TO-DATE
:compileJava
...Starts erroring out here...
我猜这是一个类路径问题,但我无法弄清楚如何修复它。
提前致谢, JM
PS:已编辑的问题,因为我能够通过2个项目构建重现问题(从3开始)
答案 0 :(得分:9)
基于Java Quckstart: Multi-project Java build:
1)您的settings.gradle
文件需要位于dev/
,而不是dev/project_A
,并且应该包含以下内容:
include 'Project_A', 'Project_B'
2)然后您的dev/Project_A/build.gradle
文件应包含
dependencies {
compile project(':Project_B')
}
修改强>
我按照您在问题中描述的项目布局创建了一个玩具示例。但是,我还没有能够重现这个问题。也许您能够发现导致您特定错误的一些差异:
目录树
├── Project_A │ ├── build.gradle │ ├── settings.gradle │ └── src │ └── main │ └── java │ └── a │ └── A.java └── Project_B ├── build.gradle └── src └── main └── java └── b └── B.java
<强> Project_A /的build.gradle 强>
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'a.A'
dependencies {
compile project(':Project_B')
}
<强> Project_A / settings.gradle 强>
includeFlat 'Project_B'
<强> A.java 强>
package a;
import b.B;
public class A {
public static void main(String[] args) {
System.out.println("From A.main...");
B.call();
}
}
<强> Project_B /的build.gradle 强>
apply plugin: 'java'
<强> B.java 强>
package b;
public class B {
public static void call() {
System.out.println("Calling B");
}
}
从Project_A
运行Gradle时,输出为:
$ gradle clean build run :clean UP-TO-DATE :Project_B:clean UP-TO-DATE :Project_B:compileJava :Project_B:processResources UP-TO-DATE :Project_B:classes :Project_B:jar :compileJava :processResources UP-TO-DATE :classes :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :check UP-TO-DATE :build :Project_B:assemble :Project_B:compileTestJava UP-TO-DATE :Project_B:processTestResources UP-TO-DATE :Project_B:testClasses UP-TO-DATE :Project_B:test UP-TO-DATE :Project_B:check UP-TO-DATE :Project_B:build :run From A.main... Calling B BUILD SUCCESSFUL
答案 1 :(得分:1)
好的,如果这对某人有用,我终于实现了删除(git rm).claspath文件。它出现在.gitignore中,但出于某种原因,它似乎已经在某个时刻进行了调整并且正在玩耍。
执行此操作并在Eclipse中重新导入项目后,一切都恢复正常。
感谢那些试图提供帮助的人。