gpt4 book ai didi

Java gradle build不重新编译源文件

转载 作者:行者123 更新时间:2023-12-01 18:10:13 24 4
gpt4 key购买 nike

我有一个 gradle java 项目。我最近将源文件重新组织到 dub 文件夹中。

原来我所有的源文件都在文件夹中...

project_root/src/main/java

现在我有 Foo.java 类...

project_root/src/main/java/folderA

我有 Bar.java 类...

project_root/src/main/java/folderB

Bar 依赖于 Foo。当我更改 Foo 类时,Bar 类不会重新编译。因为 Foo 已经改变,类 Bar 应该有编译错误,但它们没有命中。

我的build.gradle文件如下...

apply plugin: 'java'

// Use maven repository
repositories {
mavenCentral()
google()
}

dependencies {
implementation 'org.eclipse.jetty:jetty-servlet:9.4.19.v20190610'
implementation 'org.eclipse.jetty:jetty-client:9.4.19.v20190610'
implementation 'mysql:mysql-connector-java:8.0.16'
implementation 'org.apache.commons:commons-dbcp2:2.7.0'
implementation 'org.jdbi:jdbi3-core:3.10.1'
implementation 'com.google.firebase:firebase-admin:6.11.0'
compile 'com.google.apis:google-api-services-oauth2:v1-rev155-1.25.0'
// implementation 'com.google.gms:google-services:4.3.3'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'

compile project('chesslib')
runtime files('../../chesslib/build/libs/chesslib-1.1.12.jar')
}

task runServer(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'ChessServer'
}

task runClient(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'ChessClient'
standardInput = System.in // without this, using Scanner on System.in won't work
}

task runCLITestApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'CLITestApp'
standardInput = System.in
}

最佳答案

您遇到了 Gradle 中增量编译的限制,如 the documentation 中所述。 :

If there is a mismatch in the package declaration and the directory structure of source files (e.g. package foo vs location bar/MyClass.java), then incremental compilation can produce broken output. Wrong classes might be recompiled and there might be leftover class files in the output.

因此建议使用经典的包到文件夹结构或禁用增量编译:

compileJava {
options.incremental = false
}

关于Java gradle build不重新编译源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60480743/

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