添加的Gradle依赖项无法在Java类中导入

时间:2017-11-19 11:19:40

标签: java gradle import dependencies



我在servdle中添加了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中的错误:

the name mockito is marked red in the import-statement

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。

我认为" +"在我的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;
相关问题