java - Gradlew 不会在 IDEA 16.2 中添加对我的外部库(类路径)的依赖项

标签 java gradle gradlew gradle-dependencies

tl;博士;添加依赖项到 build.gradle 可以很好地下载它,但不会将其添加到 idea 中的类路径/外部库中。

大家好

我是用 java 开发 web 应用程序的新手,我试图依赖 mvnrepository.com 上的一些 jar,唯一一次将依赖项下载到外部库并添加到类路径中是当我将项目作为 gradle 导入时项目,就像每次我启动并运行一个项目并添加一个新的依赖项时,我都必须再次将整个项目导入 intellij 中。

我的 build.gradle 文件如下所示:

group 'project_name'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
// https://mvnrepository.com/artifact/com.google.inject/guice
 compile group: 'com.google.inject', name: 'guice', version: '3.0'
// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core
 compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.0.M9'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-core
 compile group: 'com.sun.jersey', name: 'jersey-core', version: '1.19.1'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-json
 compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.19.1'

// https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
 compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.23.2'

// https://mvnrepository.com/artifact/com.sun.jersey/jersey-servlet
 compile group: 'com.sun.jersey', name: 'jersey-servlet', version: '1.19.1'

// https://mvnrepository.com/artifact/com.sun.jersey/jersey-server
 compile group: 'com.sun.jersey', name: 'jersey-server', version: '1.19.1'




 testCompile group: 'junit', name: 'junit', version: '4.11'
}



task wrapper(type: Wrapper) {
    gradleVersion = '2.5'
}

当我将新的依赖项添加到列表中并运行 ./gradlew build 时,无论是否使用 --refresh-dependencies 选项,它都会下载新的依赖项,但不会将下载的文件添加到外部库/类路径,所以我无法将它们导入到java代码中。我看到一个与此类似的问题,他们接受了诸如运行之类的答案:

./gradlew idea

就我而言,这根本没有帮助,它只是在目录中添加了一些自动生成的文件,与行为没有明显的区别。

然后他们接受将项目作为 gradle 项目导入,我已经这样做了 - 这有效,但添加新的依赖项不起作用。

仅供引用,我正在使用 gradle 2.5 包装器和 IDEA 社区 16.2

最佳答案

好的。我解决/弄清楚了,显然仅仅运行构建并没有帮助, 在 intellij 内部,我必须转到 View --> Tool Windows --> Gradle,然后它会打开 gradle 窗口,我可以在其中单击刷新按钮,下载依赖项。

感谢所有看过它的人:)

关于java - Gradlew 不会在 IDEA 16.2 中添加对我的外部库(类路径)的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39078629/

相关文章:

java - 如何修复 "Failed to notify build listener"错误?

android - Android Studio中的 list 错误

gradle 插件及其依赖项

java - Cucumber-jvm 和页面对象的泛型不起作用

java - 为什么 LiveData setValue 或 PostValue 在 View 中只触发一次 onChange?

java - 以节拍为单位循环运行 Java 应用程序

gradle - Spring Boot Gradle插件,应用程序插件和Gradle 2.3包装器

java - 在 Tomcat 中配置 log4j.xml

mongodb - hadoop mongodb连接器构建失败

java - gradle 4.9-gradlew和Java 10仍然获得:无法从 '10'确定Java版本