简体   繁体   English

Java gradle build 不重新编译源文件

[英]Java gradle build not recompiling source files

I have a gradle java project.我有一个 gradle java 项目。 I recently re-organized my source files into dub folder.我最近将我的源文件重新组织到配音文件夹中。

Originally all my source files were in the folder...最初我所有的源文件都在文件夹中......

project_root/src/main/java project_root/src/main/java

Now I have Class Foo.java in...现在我有 Class Foo.java 在...

project_root/src/main/java/folderA project_root/src/main/java/folderA

and I have Class Bar.java in...我有 Class Bar.java 在...

project_root/src/main/java/folderB project_root/src/main/java/folderB

Bar is dependant on Foo. Bar 依赖于 Foo。 When I change class Foo, class Bar does no recompile.当我更改 Foo 类时,Bar 类不会重新编译。 Because Foo has changed, class Bar should have compilation errors, but they don't hit.因为Foo变了,类Bar应该有编译错误,但是没有命中。

My build.gradle file is as follows...我的 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
}

You are hitting a limitation of the incremental compilation in Gradle, as stated in the documentation :文档所述,您遇到了 Gradle 中增量编译的限制:

If there is a mismatch in the package declaration and the directory structure of source files (eg package foo vs location bar/MyClass.java), then incremental compilation can produce broken output.如果包声明和源文件的目录结构不匹配(例如包 foo 与 location bar/MyClass.java),则增量编译可能会产生损坏的输出。 Wrong classes might be recompiled and there might be leftover class files in the output.可能会重新编译错误的类,并且输出中可能会有剩余的类文件。

So the recommendation is to go with the classical package to folder structure or disable incremental compilation:所以建议使用经典包到文件夹结构或禁用增量编译:

compileJava {
  options.incremental = false
}

"When I change class Foo, class Bar does no recompile." “当我更改 Foo 类时,Bar 类不会重新编译。” It won't automatically recompile, you need to rebuild the project它不会自动重新编译,您需要重建项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM