gpt4 book ai didi

java - Gradle不维护Gradle构建中的目录层次结构

转载 作者:行者123 更新时间:2023-12-03 05:50:49 25 4
gpt4 key购买 nike

我正在使用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/javabuild/classes/groovy中的文件夹结构已更改。它将所有类文件集中到一个文件夹中-分别为 maintests。这对我来说是个问题,因为在我的 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

最佳答案

因此,如对该问题的评论所述,问题是package vectors;文件中缺少DoublyLinkedList.java

关于java - Gradle不维护Gradle构建中的目录层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47898591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com