Reputation: 11
I used gradle to build the project in an environment without internet, and I put all the project dependencies into the libs directory in the project root, and everything worked fine. Because it is a spring-boot project, I need to package it with the gradle plugin org.springframework.boot, so I put the jar of the plugin spring-boot-gradle-plugin-2.2.0.RELEASE.jar into the project's But I have used many ways from the Internet to specify the plugins in the plugins directory, but none of them work.
The project directory is as follows:
projectRoot
├── build.gradle
├── gradle
│ └── wrapper
├── gradlew
├── gradlew.bat
├── libs
│ └── xxx.jar
├── plugins
│ ├── dependency-management-plugin-1.0.11.RELEASE.jar
│ └── spring-boot-gradle-plugin-2.2.0.RELEASE.jar
├── resource
├── settings.gradle
└── src
├── main
└── test
And the settings.gradle file is as follows:
pluginManagement {
repositories {
mavenLocal()
flatDir { dirs 'plugins' }
}
}
rootProject.name = 'example'
And the build.gradle file is as follows:
plugins {
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenLocal()
}
dependencies {
implementation files('libs/xxx.jar','libs/others_of_libs.jar')
}
But when I execute it via offline mode:./gradlew build --offline
,I get the following error:
Plugin [id: 'org.springframework.boot', version: '2.2.0.RELEASE'] 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 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.2.0.RELEASE')
Searched in the following repositories:
maven(file:/User/myName/example/plugins/)
How exactly is this situation specified? Do I need to install the two jars in the plugins directory to the local maven repository?
I have found many ways to compile specified plugins offline on the web, including this:
buildscript {
repositories {
mavenLocal()
maven { url('plugins') }
}
dependencies {
classpath fileTree(include: ['*.jar'], dir: 'plugins')
classpath files('plugins/dependency-management-plugin-1.0.11.RELEASE.jar')
classpath files('plugins/spring-boot-gradle-plugin-2.2.0.RELEASE.jar')
classpath "io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.11.RELEASE"
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.0.RELEASE"
}
}
I still get the same error.
Upvotes: 1
Views: 823
Reputation: 11
My problem is solved. In response to this problem, I was inspired by the following link:Gradle Plugins Offline Resolution
In this answer from the gradle community, I learned how gradle parses plugins: ${pluginId}:${pluginId}.gradle.plugin:${pluginVersion}
.
So I changed the plugins in the plugins directory to the corresponding format.
buildscript {
dependencies {
classpath "io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.8.RELEASE"
classpath "org.springframework.boot:org.springframework.boot.gradle.plugin:2.2.0.RELEASE"
}
}
But then I ran into a new problem when I executedgradlew --offline bootJar
with the error:
FAILURE: Build failed with an exception.
* What went wrong:
org/springframework/boot/loader/tools/MainClassFinder
> org.springframework.boot.loader.tools.MainClassFinder
So I used org.springframework.boot.loader.tools.MainClassFinder class Google search, found that is spring-boot-loader-tools the contents of the jar package, I then added this jar to the plugins, and change the buildscript {...} block
buildscript {
dependencies {
classpath "io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.8.RELEASE"
classpath "org.springframework.boot:org.springframework.boot.gradle.plugin:2.2.0.RELEASE"
classpath "org.springframework.boot:spring-boot-loader-tools:2.2.0.RELEASE"
}
}
Now it works on my Mac.
But when I put the project on an environment without internet (the build environment of the final project is no internet), there are other problems, similar to a class not being found. I guess this kind of problem is the bootJar plugin execution can not find the relevant dependencies, so I copied the .m2
file from my mac, and finally built and ran successfully.
So to summarize, there are two problems:
Upvotes: 0