gradle 是否存储在 Nexus 存储库中?

问题描述 投票:0回答:4

这是用于下载 gradle 本身。我正在尝试尽可能轻松地将其缓存在公司网络内。如果 gradle 在上游的 nexus 存储库中可用,那么我可以将包装器的 distributionUrl 指向内部 nexus。

Maven 在 Maven Central 中可用,这很方便,我试图找到类似的解决方案。 https://search.maven.org/search?q=g:org.apache.maven%20a:apache-maven

我确实找到了,但我想知道是否有更官方的东西。 https://github.com/hazendaz/gradle https://search.maven.org/search?q=g:com.github.hazendaz.gradle%20a:gradle

感谢您的宝贵时间

gradle nexus
4个回答
4
投票

使用 Nexus 时,您可以为

raw (proxy)
创建
https://services.gradle.org/distributions
存储库。这将代理所有请求。

在此实例中,存储库名为

gradle-distributions
。这允许您使用:

curl https://nexus.example-organisation.com/repository/gradle-distributions/gradle-6.9.1-wrapper.jar.sha256
e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637

代替:

curl https://services.gradle.org/distributions/gradle-6.9.1-wrapper.jar.sha256
e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637

那么在

gradle-wrapper.properties
中你可以使用:

distributionUrl=https://nexus.example-organisation.com/repository/gradle-distributions/gradle-6.9.1-bin.zip

2
投票

不幸的是没有。 Gradle Wrapper JAR 未发布到 Nexus 等 Maven 存储库。

您可以在this行看到实际下载发生的地方。进一步挖掘,您可以看到here Gradle 使用较低级别的 Java 机制来下载包装器。

所有 Gradle 发行版均可在此处获取:https://services.gradle.org/distributions/。如果您查看版本信息,会发现有一个 JSON 文件,其中包含最新的发行版本。我对管理 Nexus 并不完全熟悉,但如果您可以以某种方式创建某种插件来轮询该版本信息,那么如果 Nexus 中尚未提供/缓存它,您就可以下载它。


0
投票

M.P.提供的解决方案Korstanje 不能直接为我工作,因为我的 Nexus 版本不允许我代理原始网站。但是,我可以通过创建托管“站点”存储库,然后使用以下脚本将 Gradle bin zip 上传到我的存储库来实现类似的功能:

#/bin/bash

#
# This helper script will upload any file to 'Gradle Distributions' Nexus repo
#

NEXUS_ADMIN_USER=$1
GRADLE_BIN_ZIP_FILE=$2

if    [ -z "$NEXUS_ADMIN_USER" ] \
   || [ -z "$GRADLE_BIN_ZIP_FILE" ]
then
  echo "$0 <NEXUS_ADMIN_USER> <GRADLE_BIN_ZIP_FILE>"
  exit 1
fi

curl -v \
    --user $NEXUS_ADMIN_USER \
    --upload-file $GRADLE_BIN_ZIP_FILE \
    http://nexus-host:8081/nexus/content/sites/gradle-distributions/$GRADLE_BIN_ZIP_FILE

现在所有已批准的 Gradle 发行版都可以通过 Nexus 管理的 URL 获取:

http://nexus-host:8081/nexus/content/sites/gradle-distributions/
  ├── gradle-3.5.1-bin.zip
  ├── gradle-7.4.1-bin.zip
  ├── gradle-7.4.2-bin.zip
  └── upload_gradle_distro.sh

最后一步修改

gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=http\://nexus-host\:8081/nexus/content/sites/gradle-distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0
投票

M.P.的回答Korstanje 效果很好。

@瓦尔布兰特
确保你没有火瀑布,例如。 G。公司防火墙,拒绝访问 https://services.gradle.org/distributions/

还要验证是否有任何重定向到其他网址(在本例中就是这样)。有一个重定向到 https://downloads.gradle.org/distributions/

检查浏览器开发工具,例如重定向: How to see redirect location in browser?

因此您的管理员必须取消查看这两个 URL。

© www.soinside.com 2019 - 2024. All rights reserved.