我在Gradle中将servlet api添加为依赖项,但是当我想在Java类中导入它时,它就无法工作。 Mockito框架也是如此。
我的gradle.build文件如下所示:
group 'Dontknownow'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin2js'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'org.mockito:mockito-core:2.+'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
这是我的IntelliJ中的错误样子:
最佳答案
Okey我自己解决了。
我认为build.gradle中的“+”是问题所在
而不是使用
testCompile 'org.mockito:mockito-core:2.+'
我输入了绝对版本:
testCompile 'org.mockito:mockito-core:2.7.19'
还有https://guides.gradle.org/building-java-web-applications/上Mockito的替代导入语句
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
关于java - 添加的Gradle依赖项无法在Java类中导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47376237/