如何完全离线构建gradle个项目?
How to build gradle projects completely offline?
环境:
Linux + JDK 11 + Gradle 5.0
我有几个 gradle 项目必须在没有互联网连接的情况下从源构建/例如这个 git clone --depth 1 --branch 3.0.0 https://github.com/bobbylight/RSyntaxTextArea.git
首先我在线构建了这个项目然后复制 ~/.gradle 到 $PROJECT_DIR/grdl ,接下来我想测试这个版本。我执行 gradle --stop
,清除整个 ~/.gradle 目录然后关闭互联网和 运行 以下脚本:
cp -r ./grdl/* ~/.gradle
cd RSyntaxTextArea
gradle --offline clean build
在我将这些文件移动到另一台 Linux+JDK11+Gradle 5.0
离线机器之前,一切都很好。当我 运行 相同的脚本时,出现以下错误:
./build.sh
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':RSyntaxTextArea'.
> Could not resolve all artifacts for configuration ':RSyntaxTextArea:classpath'.
> Could not download coveralls-gradle-plugin.jar (org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2): No cached version available for offline mode
> Could not download httpmime.jar (org.apache.httpcomponents:httpmime:4.3): No cached version available for offline mode
> Could not download org.eclipse.jgit.jar (org.eclipse.jgit:org.eclipse.jgit:3.6.0.201412230720-r): No cached version available for offline mode
> Could not download http-builder.jar (org.codehaus.groovy.modules.http-builder:http-builder:0.7.1): No cached version available for offline mode
> Could not download httpclient.jar (org.apache.httpcomponents:httpclient:4.3): No cached version available for offline mode
> Could not download jsch.jar (com.jcraft:jsch:0.1.50): No cached version available for offline mode
> Could not download JavaEWAH.jar (com.googlecode.javaewah:JavaEWAH:0.7.9): No cached version available for offline mode
> Could not download json-lib-jdk15.jar (net.sf.json-lib:json-lib:2.3): No cached version available for offline mode
> Could not download nekohtml.jar (net.sourceforge.nekohtml:nekohtml:1.9.16): No cached version available for offline mode
> Could not download xml-resolver.jar (xml-resolver:xml-resolver:1.2): No cached version available for offline mode
> Could not download httpcore.jar (org.apache.httpcomponents:httpcore:4.3): No cached version available for offline mode
> Could not download commons-beanutils.jar (commons-beanutils:commons-beanutils:1.8.0): No cached version available for offline mode
> Could not download commons-logging.jar (commons-logging:commons-logging:1.1.3): No cached version available for offline mode
> Could not download commons-codec.jar (commons-codec:commons-codec:1.6): No cached version available for offline mode
> Could not download commons-collections.jar (commons-collections:commons-collections:3.2.1): No cached version available for offline mode
> Could not download ezmorph.jar (net.sf.ezmorph:ezmorph:1.0.6): No cached version available for offline mode
> Could not download commons-lang.jar (commons-lang:commons-lang:2.4): No cached version available for offline mode
> Could not download xercesImpl.jar (xerces:xercesImpl:2.9.1): No cached version available for offline mode
> Could not download xml-apis.jar (xml-apis:xml-apis:1.3.04): No cached version available for offline mode
五个 gradle 项目中有四个有类似问题。令人惊讶的是,一台机器在两台机器上都正常脱机,这台机器 - git clone --depth 1 --branch 0.27 https://github.com/JFormDesigner/FlatLaf.git
。我认为我没有正确理解 gradle 缓存。你能帮我在没有互联网的情况下构建 gradle 个项目吗?它可以是 Gradle 的任何版本,但我绑定到 Linux + JDK 11.
我认为您遇到了这个问题:https://github.com/gradle/gradle/issues/1338
也就是说,缓存项不可重定位。复制整个 ~/.gradle
文件夹可能还不够,尤其是当 ~
解析到与原始计算机不同的路径(即不同的用户)时。完整路径需要完全相同(Gradle 5.0)。
然而,该问题表明版本 6.1 使缓存可重定位,因此您可能会更幸运地使用最新版本(7.2 是目前最新的版本)。
编辑:The release notes and these docs 确认从版本 6.1.1 开始可以跨部署复制缓存。
对我有用的一个解决方案是复制 $'username'/.gradle/caches/modules-2/files-2.1
文件夹
这包含 gradle 已缓存并可以重复使用的所有库。
我认为这对于 gradle versons < gradle 6.1.
是不可能的
复制 files-2.1 文件夹后,您可以将 gradle 项目与打开 intellij/eclipse 的离线模式同步。
如果还是不行,复制整个caches
文件夹。
环境:
Linux + JDK 11 + Gradle 5.0
我有几个 gradle 项目必须在没有互联网连接的情况下从源构建/例如这个 git clone --depth 1 --branch 3.0.0 https://github.com/bobbylight/RSyntaxTextArea.git
首先我在线构建了这个项目然后复制 ~/.gradle 到 $PROJECT_DIR/grdl ,接下来我想测试这个版本。我执行 gradle --stop
,清除整个 ~/.gradle 目录然后关闭互联网和 运行 以下脚本:
cp -r ./grdl/* ~/.gradle
cd RSyntaxTextArea
gradle --offline clean build
在我将这些文件移动到另一台 Linux+JDK11+Gradle 5.0
离线机器之前,一切都很好。当我 运行 相同的脚本时,出现以下错误:
./build.sh
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':RSyntaxTextArea'.
> Could not resolve all artifacts for configuration ':RSyntaxTextArea:classpath'.
> Could not download coveralls-gradle-plugin.jar (org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2): No cached version available for offline mode
> Could not download httpmime.jar (org.apache.httpcomponents:httpmime:4.3): No cached version available for offline mode
> Could not download org.eclipse.jgit.jar (org.eclipse.jgit:org.eclipse.jgit:3.6.0.201412230720-r): No cached version available for offline mode
> Could not download http-builder.jar (org.codehaus.groovy.modules.http-builder:http-builder:0.7.1): No cached version available for offline mode
> Could not download httpclient.jar (org.apache.httpcomponents:httpclient:4.3): No cached version available for offline mode
> Could not download jsch.jar (com.jcraft:jsch:0.1.50): No cached version available for offline mode
> Could not download JavaEWAH.jar (com.googlecode.javaewah:JavaEWAH:0.7.9): No cached version available for offline mode
> Could not download json-lib-jdk15.jar (net.sf.json-lib:json-lib:2.3): No cached version available for offline mode
> Could not download nekohtml.jar (net.sourceforge.nekohtml:nekohtml:1.9.16): No cached version available for offline mode
> Could not download xml-resolver.jar (xml-resolver:xml-resolver:1.2): No cached version available for offline mode
> Could not download httpcore.jar (org.apache.httpcomponents:httpcore:4.3): No cached version available for offline mode
> Could not download commons-beanutils.jar (commons-beanutils:commons-beanutils:1.8.0): No cached version available for offline mode
> Could not download commons-logging.jar (commons-logging:commons-logging:1.1.3): No cached version available for offline mode
> Could not download commons-codec.jar (commons-codec:commons-codec:1.6): No cached version available for offline mode
> Could not download commons-collections.jar (commons-collections:commons-collections:3.2.1): No cached version available for offline mode
> Could not download ezmorph.jar (net.sf.ezmorph:ezmorph:1.0.6): No cached version available for offline mode
> Could not download commons-lang.jar (commons-lang:commons-lang:2.4): No cached version available for offline mode
> Could not download xercesImpl.jar (xerces:xercesImpl:2.9.1): No cached version available for offline mode
> Could not download xml-apis.jar (xml-apis:xml-apis:1.3.04): No cached version available for offline mode
五个 gradle 项目中有四个有类似问题。令人惊讶的是,一台机器在两台机器上都正常脱机,这台机器 - git clone --depth 1 --branch 0.27 https://github.com/JFormDesigner/FlatLaf.git
。我认为我没有正确理解 gradle 缓存。你能帮我在没有互联网的情况下构建 gradle 个项目吗?它可以是 Gradle 的任何版本,但我绑定到 Linux + JDK 11.
我认为您遇到了这个问题:https://github.com/gradle/gradle/issues/1338
也就是说,缓存项不可重定位。复制整个 ~/.gradle
文件夹可能还不够,尤其是当 ~
解析到与原始计算机不同的路径(即不同的用户)时。完整路径需要完全相同(Gradle 5.0)。
然而,该问题表明版本 6.1 使缓存可重定位,因此您可能会更幸运地使用最新版本(7.2 是目前最新的版本)。
编辑:The release notes and these docs 确认从版本 6.1.1 开始可以跨部署复制缓存。
对我有用的一个解决方案是复制 $'username'/.gradle/caches/modules-2/files-2.1
文件夹
这包含 gradle 已缓存并可以重复使用的所有库。 我认为这对于 gradle versons < gradle 6.1.
是不可能的复制 files-2.1 文件夹后,您可以将 gradle 项目与打开 intellij/eclipse 的离线模式同步。
如果还是不行,复制整个caches
文件夹。