无法在Intellij中导入Gradle的ShadowJar插件

时间:2018-11-29 19:16:30

标签: gradle intellij-idea gradle-plugin shadowjar

我正在尝试设置阴影罐插件以在我的Gradle项目中使用。按照说明,我将其导入为:

plugins {
    id 'com.github.johnrengelman.shadow' version '4.0.2'
}

但是,当构建开始时,出现以下错误:

Plugin [id: 'com.github.johnrengelman.shadow', version: '4.0.2'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:4.0.2')
  Searched in the following repositories:
    Gradle Central Plugin Repository

在configure build中研究堆栈跟踪时,我也发现了这一点:

org.gradle.internal.resource.transport.http.HttpRequestException: Could not HEAD 'https://plugins.gradle.org/m2/com/github/johnrengelman/shadow/com.github.johnrengelman.shadow.gradle.plugin/4.0.2/com.github.johnrengelman.shadow.gradle.plugin-4.0.2.pom'.

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to plugins.gradle.org:443 [plugins.gradle.org/104.16.175.166, plugins.gradle.org/104.16.173.166, plugins.gradle.org/104.16.172.166, plugins.gradle.org/104.16.171.166, plugins.gradle.org/104.16.174.166] failed: Connection timed out: connect

基于此,我假设我的机器与插件存储库之间有问题。我在公司代理后面工作,所以我想知道是否有任何解决方法?

编辑:这是我的存储库声明代码的结构。出于安全考虑,我宁愿不共享实际的网址:

repositories {
    maven { url 'corporate.repo.url.here:port' }
}

经过仔细检查,看来该存储库是正确的,因此应将插件下载到我的本地Maven存储库中。并非如此,我认为这是我迁移到Gradle所致。 Gradle中有任何设置可以处理吗?

1 个答案:

答案 0 :(得分:1)

我知道了。在settings.gradle中,我需要在pluginManagement中设置存储库以覆盖gradle的默认行为。

pluginManagement {
    repositories {
        maven {
            url 'corporate.repo.url.here'
        }
    }
}

默认情况下,gradle希望转到plugins.gradle.org;但是,我怀疑我正在使用的代理阻止了这种情况。因此,我需要上面的代码将其指向网络存储库。