Skip to content

Commit 34a1b5a

Browse files
Dermot SmythDermot Smyth
authored andcommitted
Create examples for disconnected (offline) projects that uses the plugins dsl #343
#343
1 parent ba91562 commit 34a1b5a

File tree

9 files changed

+395
-0
lines changed

9 files changed

+395
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Disconnected Gradle project that uses the Gradle Plugins Framework
2+
3+
This project will download all of the required dependencies (including plugins) into the 'project-maven-repo' directory in the project.
4+
5+
It does this by setting the 'gradle.user.home' to a local project directory and downloading all the project dependencies into this directory. The cache within this directory is then converted into a maven-repo format directory ('project-maven-repo') that will be used when running in a 'disconnected' mode
6+
7+
Optionally an "offline zip" file can be created that contains the project and all it's dependencies. This zip can be copied to another server and unzipped for running in disconnected mode.
8+
9+
## Usage
10+
11+
### Download Dependencies
12+
13+
The command below will download all the project dependencies (including plugins) into the 'project-maven-repo' directory
14+
15+
```
16+
gradle -Dgradle.user.home=project-gradle-cache downloadToProjectMavenRepo
17+
```
18+
19+
### Run in 'disconnected' mode
20+
21+
You just need to set the disconnected project property when running your gradle tasks. E.g. -
22+
23+
```
24+
gradle tasks -Pdisconnected
25+
```
26+
27+
or
28+
29+
```
30+
gradle mlDeploy -Pdisconnected
31+
```
32+
33+
This will use the jars that you have already downloaded to 'project-maven-repo'
34+
35+
36+
### Create 'Offline' Zip
37+
38+
This zip can be copied to another server and unzipped for running in disconnected mode.
39+
40+
```
41+
gradle -Dgradle.user.home=project-gradle-cache makeOfflineZip
42+
```
43+
44+
The zip will be created in the directory
45+
* build/distributions/offline
46+
47+
## Customise
48+
49+
**IMPORTANT**: If you want to include dependencies for a configuration (e.g. compile, runtime, mlcp etc), then you need to modify the 'downloadToProjectMavenRepo' task to include the relevant configuration. E.g. by adding 'configurations.compile.files' to the beginning of the task, all of the dependencies for the 'compile' task will be downloaded.
50+
51+
E.g. (assuming you are using the java plugin), the configuration below will download all the compile and runtime dependencies that you have defined
52+
53+
```
54+
task downloadToProjectMavenRepo(type: Copy) {
55+
configurations.compile.files
56+
configurations.runtime.files
57+
...
58+
```
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
plugins {
2+
id 'java'
3+
id 'net.saliman.properties' version '1.4.6'
4+
id 'com.marklogic.ml-gradle' version '3.6.3'
5+
}
6+
7+
repositories {
8+
// To use gradle in disconnected mode, you just need to set the 'disconnected' property. E.g. gradle compileJava -Pdisconnected
9+
if ( project.hasProperty("disconnected") && !"FALSE".equalsIgnoreCase(this.properties['disconnected'])) {
10+
println "Using offline repositories"
11+
maven {url uri( 'project-maven-repo' ) }
12+
} else {
13+
println "Using online repositories"
14+
jcenter()
15+
maven { url "https://developer.marklogic.com/maven2/" }
16+
}
17+
}
18+
19+
configurations {
20+
mlcp
21+
}
22+
23+
dependencies {
24+
// sample java compile dependency
25+
compile 'com.marklogic:marklogic-xcc:9.0.4'
26+
27+
//sample mlcp
28+
mlcp "com.marklogic:mlcp:9.0.5"
29+
}
30+
31+
32+
/**
33+
* START: Disconnected gradle tasks
34+
*/
35+
gradle.taskGraph.whenReady { graph ->
36+
if (graph.hasTask(makeOfflineZip)) {
37+
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir,"project-gradle-cache"))) {
38+
throw new GradleException("Please set the gradle user home property to 'project-gradle-cache' on the gradle command line - e.g. \n " +
39+
"gradle -Dgradle.user.home=project-gradle-cache makeOfflineZip")
40+
}
41+
}
42+
if (graph.hasTask(downloadToProjectMavenRepo)) {
43+
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir,"project-gradle-cache"))) {
44+
throw new GradleException("Please set the gradle user home property to 'project-gradle-cache' on the gradle command line - e.g. \n " +
45+
"gradle -Dgradle.user.home=project-gradle-cache downloadToProjectMavenRepo")
46+
}
47+
}
48+
}
49+
50+
task downloadToProjectMavenRepo(type: Copy) {
51+
/*
52+
* Include any configuration dependencies here that you want to copy the dependencies for.
53+
* These are defined in the 'dependencies' block. E.g. you need to include
54+
* configurations.compile.files if you want your java 'compile' dependencies downloaded
55+
*/
56+
//configurations.runtime.files
57+
configurations.compile.files
58+
configurations.mlcp.files
59+
60+
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1') // correct as of gradle 4.7
61+
into 'project-maven-repo'
62+
eachFile {
63+
List<String> parts = it.path.split('/')
64+
it.path = (parts[0].replace('.','/') + '/' + parts[1]) + '/' + parts[2] + '/' + parts[4]
65+
}
66+
includeEmptyDirs false
67+
}
68+
69+
task makeOfflineZip(type: Zip, dependsOn: downloadToProjectMavenRepo) {
70+
from rootDir
71+
excludes = ['.tmp','.gradle','build','project-gradle-cache']
72+
destinationDir(file('build/distributions'))
73+
archiveName = 'offline.zip'
74+
doLast {
75+
println "Created offline project zip at build/distributions/offline.zip"
76+
}
77+
}
78+
79+
/**
80+
* END: Disconnected gradle tasks
81+
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pluginManagement {
2+
repositories {
3+
if ( this.properties.containsKey('disconnected') && !"FALSE".equalsIgnoreCase(this.properties['disconnected'])) {
4+
println "Using offline plugin repository"
5+
maven {url uri('project-maven-repo') }
6+
} else {
7+
println "Using online plugin repository"
8+
gradlePluginPortal()
9+
}
10+
}
11+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Disconnected Gradle project that uses the Gradle Plugins Framework
2+
3+
This project will download all of the required dependencies (including plugins) into the 'project-maven-repo' directory in the project.
4+
5+
It does this by setting the 'gradle.user.home' to a local project directory and downloading all the project dependencies into this directory. The cache within this directory is then converted into a maven-repo format directory ('project-maven-repo') that will be used when running in a 'disconnected' mode
6+
7+
8+
## Usage
9+
10+
### Download Dependencies
11+
12+
The command below will download all the project dependencies (including plugins) into the 'project-maven-repo' directory
13+
14+
```
15+
gradle -Dgradle.user.home=project-gradle-cache downloadToProjectMavenRepo
16+
```
17+
18+
### Run in 'disconnected' mode
19+
20+
You just need to set the disconnected project property when running your gradle tasks. E.g. -
21+
22+
```
23+
gradle tasks -Pdisconnected
24+
```
25+
26+
or
27+
28+
```
29+
gradle mlDeploy -Pdisconnected
30+
```
31+
32+
This will use the jars that you have already downloaded to 'project-maven-repo'
33+
34+
## Customise
35+
36+
**IMPORTANT**: If you want to include dependencies for a configuration (e.g. compile, runtime, mlcp etc), then you need to modify the 'downloadToProjectMavenRepo' task to include the relevant configuration. E.g. by adding 'configurations.compile.files' to the beginning of the task, all of the dependencies for the 'compile' task will be downloaded.
37+
38+
E.g. (assuming you are using the java plugin), the configuration below will download all the compile and runtime dependencies that you have defined
39+
40+
```
41+
task downloadToProjectMavenRepo(type: Copy) {
42+
configurations.compile.files
43+
configurations.runtime.files
44+
...
45+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
plugins {
2+
id 'net.saliman.properties' version '1.4.6'
3+
id 'com.marklogic.ml-gradle' version '3.6.3'
4+
}
5+
6+
repositories {
7+
// To use gradle in disconnected mode, you just need to set the 'disconnected' property. E.g. gradle compileJava -Pdisconnected
8+
if ( project.hasProperty("disconnected") && !"FALSE".equalsIgnoreCase(this.properties['disconnected'])) {
9+
println "Using offline repositories"
10+
maven {url uri( 'project-maven-repo' ) }
11+
} else {
12+
println "Using online repositories"
13+
jcenter()
14+
maven { url "https://developer.marklogic.com/maven2/" }
15+
}
16+
}
17+
18+
19+
20+
/**
21+
* START: Disconnected gradle tasks
22+
*/
23+
24+
gradle.taskGraph.whenReady { graph ->
25+
if (graph.hasTask(downloadToProjectMavenRepo)) {
26+
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir,"project-gradle-cache"))) {
27+
throw new GradleException("Please set the gradle user home property to 'project-gradle-cache' on the gradle command line - e.g. \n " +
28+
"gradle -Dgradle.user.home=project-gradle-cache downloadToProjectMavenRepo")
29+
}
30+
}
31+
}
32+
33+
task downloadToProjectMavenRepo(type: Copy) {
34+
/*
35+
* Include any configuration dependencies here that you want to copy the dependencies for.
36+
* These are defined in the 'dependencies' block. E.g. you need to include
37+
* configurations.compile.files if you want your java 'compile' dependencies downloaded
38+
*/
39+
//configurations.compile.files
40+
41+
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1') // correct as of gradle 4.7
42+
into 'project-maven-repo'
43+
eachFile {
44+
List<String> parts = it.path.split('/')
45+
it.path = (parts[0].replace('.','/') + '/' + parts[1]) + '/' + parts[2] + '/' + parts[4]
46+
}
47+
includeEmptyDirs false
48+
}
49+
50+
/**
51+
* END: Disconnected gradle tasks
52+
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pluginManagement {
2+
repositories {
3+
if ( this.properties.containsKey('disconnected') && !"FALSE".equalsIgnoreCase(this.properties['disconnected'])) {
4+
println "Using offline plugin repository"
5+
maven {url uri('project-maven-repo') }
6+
} else {
7+
println "Using online plugin repository"
8+
gradlePluginPortal()
9+
}
10+
}
11+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Disconnected Gradle project that uses the Gradle Plugins Framework
2+
3+
This project will download all of the required dependencies (including plugins) into the 'project-maven-repo' directory in the project.
4+
5+
It does this by setting the 'gradle.user.home' to a local project directory and downloading all the project dependencies into this directory. The cache within this directory is then converted into a maven-repo format directory ('project-maven-repo') that will be used when running in a 'disconnected' mode
6+
7+
Optionally an "offline zip" file can be created that contains the project and all it's dependencies. This zip can be copied to another server and unzipped for running in disconnected mode.
8+
9+
## Usage
10+
11+
### Download Dependencies
12+
13+
The command below will download all the project dependencies (including plugins) into the 'project-maven-repo' directory
14+
15+
```
16+
gradle -Dgradle.user.home=project-gradle-cache downloadToProjectMavenRepo
17+
```
18+
19+
### Run in 'disconnected' mode
20+
21+
You just need to set the disconnected project property when running your gradle tasks. E.g. -
22+
23+
```
24+
gradle tasks -Pdisconnected
25+
```
26+
27+
or
28+
29+
```
30+
gradle mlDeploy -Pdisconnected
31+
```
32+
33+
This will use the jars that you have already downloaded to 'project-maven-repo'
34+
35+
36+
### Create 'Offline' Zip
37+
38+
This zip can be copied to another server and unzipped for running in disconnected mode.
39+
40+
```
41+
gradle -Dgradle.user.home=project-gradle-cache makeOfflineZip
42+
```
43+
44+
The zip will be created in the directory
45+
* build/distributions/offline
46+
47+
## Customise
48+
49+
**IMPORTANT**: If you want to include dependencies for a configuration (e.g. compile, runtime, mlcp etc), then you need to modify the 'downloadToProjectMavenRepo' task to include the relevant configuration. E.g. by adding 'configurations.compile.files' to the beginning of the task, all of the dependencies for the 'compile' task will be downloaded.
50+
51+
E.g. (assuming you are using the java plugin), the configuration below will download all the compile and runtime dependencies that you have defined
52+
53+
```
54+
task downloadToProjectMavenRepo(type: Copy) {
55+
configurations.compile.files
56+
configurations.runtime.files
57+
...
58+
```
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
plugins {
2+
id 'net.saliman.properties' version '1.4.6'
3+
id 'com.marklogic.ml-gradle' version '3.6.3'
4+
}
5+
6+
repositories {
7+
// To use gradle in disconnected mode, you just need to set the 'disconnected' property. E.g. gradle compileJava -Pdisconnected
8+
if ( project.hasProperty("disconnected") && !"FALSE".equalsIgnoreCase(this.properties['disconnected'])) {
9+
println "Using offline repositories"
10+
maven {url uri( 'project-maven-repo' ) }
11+
} else {
12+
println "Using online repositories"
13+
jcenter()
14+
maven { url "https://developer.marklogic.com/maven2/" }
15+
}
16+
}
17+
18+
19+
20+
21+
/**
22+
* START: Disconnected gradle tasks
23+
*/
24+
gradle.taskGraph.whenReady { graph ->
25+
if (graph.hasTask(makeOfflineZip)) {
26+
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir,"project-gradle-cache"))) {
27+
throw new GradleException("Please set the gradle user home property to 'project-gradle-cache' on the gradle command line - e.g. \n " +
28+
"gradle -Dgradle.user.home=project-gradle-cache makeOfflineZip")
29+
}
30+
}
31+
if (graph.hasTask(downloadToProjectMavenRepo)) {
32+
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir,"project-gradle-cache"))) {
33+
throw new GradleException("Please set the gradle user home property to 'project-gradle-cache' on the gradle command line - e.g. \n " +
34+
"gradle -Dgradle.user.home=project-gradle-cache downloadToProjectMavenRepo")
35+
}
36+
}
37+
}
38+
39+
task downloadToProjectMavenRepo(type: Copy) {
40+
/*
41+
* Include any configuration dependencies here that you want to copy the dependencies for.
42+
* These are defined in the 'dependencies' block. E.g. you need to include
43+
* configurations.compile.files if you want your java 'compile' dependencies downloaded
44+
*/
45+
//configurations.compile.files
46+
47+
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1') // correct as of gradle 4.7
48+
into 'project-maven-repo'
49+
eachFile {
50+
List<String> parts = it.path.split('/')
51+
it.path = (parts[0].replace('.','/') + '/' + parts[1]) + '/' + parts[2] + '/' + parts[4]
52+
}
53+
includeEmptyDirs false
54+
}
55+
56+
task makeOfflineZip(type: Zip, dependsOn: downloadToProjectMavenRepo) {
57+
from rootDir
58+
excludes = ['.tmp','.gradle','build','project-gradle-cache']
59+
destinationDir(file('build/distributions'))
60+
archiveName = 'offline.zip'
61+
doLast {
62+
println "Created offline project zip at build/distributions/offline.zip"
63+
}
64+
}
65+
66+
/**
67+
* END: Disconnected gradle tasks
68+
*/

0 commit comments

Comments
 (0)