我正在使用gradle来构建它。文件夹结构如下:
java_data_structures
├── build.gradle
├── build
| ├── classes
| | ├── groovy
| | | └── test
| | | └── DoublyLinkedListSpec.class
| | └── java
| | └── main
| | ├── Application.class
| | └── DoublyLinkedList.class
| ├── distributions
| └── other
|
└── src
├── main
│ └── java
│ ├── Application.java
│ ├── graphs
│ ├── maps
│ ├── matricies
│ ├── sets
│ ├── trees
│ ├── vectors
│ | └── DoublyLinkedList.java
│ └── Application.java
└── test
└── groovy
└── vectors
└── DoublyLinkedListSpec.groovy
问题是,build/classes/java
和build/classes/groovy
中的文件夹结构已更改。它只是将所有类文件归为一个文件夹 - main
和tests
。这对我来说是一个问题,因为在我的Application.java
文件中,我有以下代码:
public class Application {
public static void main(String[] args) {
DoublyLinkedList<Integer> list;
Integer[] array = {1, 2, 3};
list = new DoublyLinkedList<Integer>(array);
System.out.println(list);
}
}
我可以在不使用DoublyLinkedList
语句的情况下访问import
。我希望我的代码看起来像这样:
import vectors.DoublyLinkedList;
public class Application {
public static void main(String[] args) {
DoublyLinkedList<Integer> list;
Integer[] array = {1, 2, 3};
list = new DoublyLinkedList<Integer>(array);
System.out.println(list);
}
}
但是,当我使用上面的代码运行gradle build
时,我收到以下错误:
> Task :compileJava
/Users/jod/java_data_structures/src/main/java/Application.java:1: error: package vectors does not exist
import vectors.DoublyLinkedList;
^
1 error
FAILURE: Build failed with an exception.
这是可以预料到的,因为build/classes/java/main
文件夹的结构具有彼此相邻的所有类文件而没有它们各自的文件夹。我的gradle.build
文件如下:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = "Application"
jar {
baseName = 'java_data_structures'
version = '0.0.1'
}
repositories {
mavenCentral()
}
dependencies {
testCompile(
'junit:junit:4.12',
'org.codehaus.groovy:groovy-all:2.4.4',
'org.spockframework:spock-core:1.0-groovy-2.4',
'org.springframework.boot:spring-boot:1.2.1.RELEASE',
'cglib:cglib-nodep:2.2.2'
)
}
javadoc {
destinationDir = new File("${projectDir}/doc/javadoc")
source = sourceSets.main.allJava
classpath = configurations.compile
}
我需要做什么才能使我的文件夹层次结构保持不变?这是我想要的结构:
java_data_structures
├── build.gradle
├── build
| ├── classes
| | ├── groovy
| | | └── test
| | | └── vectors
| | | └── DoublyLinkedList.class
| | └── java
| | └── main
| | ├── Application.class
| | └── vectors
| | └── DoublyLinkedList.class
| ├── distributions
| └── other
|
└── src
├── main
│ └── java
│ ├── Application.java
│ ├── graphs
│ ├── maps
│ ├── matricies
│ ├── sets
│ ├── trees
│ ├── vectors
│ | └── DoublyLinkedList.java
│ └── Application.java
└── test
└── groovy
└── vectors
└── DoublyLinkedListSpec.groovy
答案 0 :(得分:0)
正如问题评论中所示,问题是package vectors;
文件中缺少DoublyLinkedList.java
。