java Gradle:无法在 Intellij 中设置未知属性“classDumpFile”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48959264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle: could not set unknown property 'classDumpFile' in Intellij
提问by Oscar Reyes
I have been searching through the Internet and asking on irc chats but none of them were or did not give any answer for trying to solve my problem.
我一直在互联网上搜索并询问 irc 聊天,但他们都没有或没有给出任何试图解决我的问题的答案。
I am trying to make my project to use JaCoCo
on Intellij
IDE, the tests are going to be done in a Jenkins
server, i have set some settings in my gradle.build file for JaCoCo
but build compilation fails saying Could not set unknown property 'classDumpFile' for object of type org.gradle.testing.jacoco.plugins.JacocoTaskExtension.
我试图让我的项目JaCoCo
在Intellij
IDE上使用,测试将在Jenkins
服务器中完成,我在我的 gradle.build 文件中设置了一些设置,JaCoCo
但构建编译失败说Could not set unknown property 'classDumpFile' for object of type org.gradle.testing.jacoco.plugins.JacocoTaskExtension.
The build file is like this:
构建文件是这样的:
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'jacoco'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
jacoco{
toolVersion = '0.7.6.201602180812'
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
compile group: 'org.json', name: 'json', version: '20180130'
}
test{
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}
this is a gradle file generated by IntelliJ
when creating the project and i have been adding some dependencies manually, now the developer that is managing the jenkins
server told me to use these JaCoCo
settings for sonarQube
to work well, IntelliJ
fails to make any compilation but when submitting the code to Jenkins
it works fine.
这是IntelliJ
创建项目时生成的gradle 文件,我一直在手动添加一些依赖项,现在管理jenkins
服务器的开发人员告诉我使用这些JaCoCo
设置sonarQube
才能正常工作,但IntelliJ
无法进行任何编译,但是在将代码提交到Jenkins
它工作正常。
I have been searching why does this happens and i have found out this might be due to gradle version and should use classDumpDir
instead, this makes IntelliJ
work but Jenkins
server fails to build the project.
我一直在寻找为什么会发生这种情况,我发现这可能是由于 gradle 版本造成的,应该classDumpDir
改用,这可以IntelliJ
工作,但Jenkins
服务器无法构建项目。
I believe this might be due to gradle version or something but i am still learning how to work with Java
and IntelliJ
, other developers are working with Eclipse
and they do not get this error but i don't want to switch to Eclipse
cause i am already too comfortable with IntelliJ
我相信这可能是由于 gradle 版本或其他原因,但我仍在学习如何使用Java
和IntelliJ
,其他开发人员正在使用Eclipse
并且他们没有收到此错误但我不想切换到Eclipse
因为我已经太舒服了IntelliJ
In case is necessary here are the versions i am using:
如果有必要,这里是我正在使用的版本:
- CLI Gradle version: 2.10
- Java version: Ubuntu openjdk 1.8.0_151
- IntelliJ version: 2017.3.4 Community Edition
- CLI Gradle 版本:2.10
- Java 版本:Ubuntu openjdk 1.8.0_151
- IntelliJ 版本:2017.3.4 社区版
采纳答案by Oscar Reyes
After long hours of searching, testing and failing i have finally found the way to fix this issue.
经过长时间的搜索、测试和失败,我终于找到了解决这个问题的方法。
I have found out in the directory gradle/wrapper
there is a file with the gradle properties, in this file there was a variable that defines which gradle to use and on my file it was set to use gradle 4.5:
我发现在目录中gradle/wrapper
有一个带有 gradle 属性的文件,在这个文件中有一个定义要使用哪个 gradle 的变量,在我的文件中它被设置为使用 gradle 4.5:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
i've asked the DevOps engineer which gradle version jenkins is using and he said it should be 3.0 so i changed the distributionUrl
value to use 3.0 version and it works
我问过 DevOps 工程师 jenkins 正在使用哪个 gradle 版本,他说它应该是 3.0,所以我将distributionUrl
值更改为使用 3.0 版本并且它有效
回答by djgooner
Looks like they changed the Variable, from classDumpFile to classDumpDir.
看起来他们改变了变量,从 classDumpFile 到 classDumpDir。
test {
jacoco {
append = false
**classDumpDir** = file("$buildDir/jacoco/classpathdumps")
}
}
This worked for me
这对我有用