gradle - Intellij gradle package name incorrect error
问题描述
I have just opened this (https://github.com/codetojoy/easter_eggs_for_gradle/tree/master/egg_StackOverflow_51685286) project in IntelliJ with the following files:
src/net/codetojoy/Foo.java
src/net/codetojoy/service/FooService.java
src/net/codetojoy/tests/FooServiceTestCase.java
and build.gradle
contains a configuration for sourceSets like so:
sourceSets {
main {
java {
srcDir 'src'
exclude 'net/codetojoy/tests/*'
}
}
}
sourceSets.test.java.srcDir 'src/net/codetojoy/tests'
and On the FooServiceTestCase.java
file, I am getting an error on the package line saying Package name 'net.codetojoy.tests' does not correspond to the file path
.
I think it is because of the customised source and test set. But I am unsure how to fix it....
please help
解决方案
源集test
定义需要看起来更像main
一个:
sourceSets {
main {
java {
srcDir 'src'
exclude 'net/codetojoy/tests/*'
}
}
test {
java {
srcDir 'src'
include 'net/codetojoy/tests/*
}
}
上一个答案在命令行中起作用但在 IDE 中不起作用的原因是,对于 Java 编译器,源文件的位置无关紧要。该package
指令用于正确放置生成的class
文件,但源文件不必位于匹配的目录结构中。但通常 IDE 会执行此检查。
推荐阅读
- r - 在 R 中缩放数据 - 我需要缩放数据框以避免前 9 列,但最终缩放的文件需要具有前 9 列
- r - 信息矩阵是奇异的,在 R (Lavaan)
- css - 从下到上显示聊天消息
- kubernetes - 基于 Kubernetes 命令的活性探针
- c++ - C++:SDL 音频回调最终停止工作
- python - 如何根据 Pandas 未来的值检查列中的值
- python - 如何解决 IndexError:在 ConvNet 中用作索引的数组必须是整数(或布尔)类型?
- xslt - 下面的代码是做什么的?
- javascript - 通过用户脚本单击页面上的属性
- google-apps-script - 如何让 Appscript 识别合并来自不同电子表格行的相同值的关联数组