Skip to content

Commit 4428c50

Browse files
committed
Merge branch 'dev'
2 parents d1660cb + aa14704 commit 4428c50

File tree

24 files changed

+888
-3
lines changed

24 files changed

+888
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
.gradle
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Standalone Gradle deployer with ml-gradle
2+
3+
## Quickstart
4+
5+
Summary of the steps required. See sections below for more detailed steps
6+
7+
*NOTE:* The use of gradlew is required
8+
9+
1. Create standalone deployer zip
10+
```
11+
./gradlew makeOfflineZip
12+
```
13+
2. Copy zip (build/distributions/offline.zip) to desired location / server and unzip
14+
15+
3. Run disconnected tasks from unzip location
16+
```
17+
./gradlew mlDeploy -Pdisconnected=true
18+
```
19+
20+
21+
## Overview
22+
23+
An example of how to create a completely self-contained deployer zip that contains:
24+
25+
1. All of the plugin / dependencies required to run the deployment (including ml-gradle)
26+
2. The Gradle distribution
27+
28+
Once the zip has been created, you only need Java to run the deployment tasks.
29+
30+
This approach is useful when you need to create a package that does not require any external resources (e.g. Maven/Gradle repositories) to perform deployment operations.
31+
32+
## Requirements
33+
34+
* Java 8/9
35+
* Internet connection (for creation of zip only)
36+
37+
38+
## How it works
39+
40+
This project will:
41+
42+
* Download all of the required dependencies (including plugins) into the 'build/offline/maven-repo' directory in the project
43+
* Download the Gradle binary distribution (zip) into the 'build/offline/gradle/wrapper' directory in the project
44+
* Create an offline.zip in build/distributions that contains
45+
* the Gradle project itself
46+
* all of the required dependencies
47+
* the Gradle distribution that works with the gradlew executable
48+
49+
50+
## Usage
51+
52+
*NOTE:* It is important to use the gradlew executable as it will download the Gradle distribution that will be incorporated into the self-contained deployer zip.
53+
54+
## 1. Create the self-contained deployer zip
55+
56+
*NOTE:* This needs to be executed from a machine with access to the internet. It will create the zip at the location build/distributions/offline.zip
57+
58+
#### Linux / Mac
59+
60+
```
61+
./gradlew makeOfflineZip
62+
```
63+
64+
#### Windows
65+
66+
```
67+
gradlew makeOfflineZip
68+
```
69+
70+
71+
## 2. Unzip the distribution
72+
73+
Copy the created offline.zip to the desired location and unzip
74+
75+
```
76+
unzip offline.zip
77+
```
78+
79+
## 3. Execute disconnected the Gradle tasks
80+
81+
From the directory that you have unzipped the offline.zip file into
82+
83+
```
84+
./gradlew mlDeploy -Pdisconnected=true
85+
```
86+
87+
This will use the jars that you have already downloaded to 'build/offline/maven-repo'
88+
89+
## Customise
90+
91+
**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.
92+
93+
E.g. (assuming you are using the Java plugin), the configuration below will download all the compile and runtime dependencies that you have defined:
94+
95+
```
96+
task downloadToProjectMavenRepo(type: Copy) {
97+
configurations.compile.files
98+
configurations.runtime.files
99+
...
100+
```
101+
102+
## Use own gradle instance (rather than gradlew)
103+
104+
If you want to install gradle instead of bundling gradle wrapper (gradlew) with the offline.zip, you can do that too using the following steps
105+
106+
1. Remove build directory (to ensure that no gradlew zip exists in the build dir)
107+
108+
2. Create deployer zip
109+
```
110+
gradle -Dgradle.user.home=build/gradle-home makeOfflineZip
111+
```
112+
3. Copy zip (build/distributions/offline.zip) to desired location / server and unzip
113+
114+
4. Run disconnected tasks from unzip location
115+
```
116+
gradle mlDeploy -Pdisconnected=true
117+
```
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
plugins {
2+
id 'java' //optional - delete if not needed
3+
id 'net.saliman.properties' version '1.4.6'
4+
id 'com.marklogic.ml-gradle' version '3.7.1'
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(disconnected)) {
10+
println "Using offline repositories"
11+
maven { url uri(projectMavenRepo) }
12+
} else {
13+
println "Using online repositories"
14+
jcenter()
15+
maven { url "https://developer.marklogic.com/maven2/" }
16+
}
17+
}
18+
19+
configurations {
20+
mlcp //example if you want to use mlcp. Delete otherwise
21+
}
22+
23+
dependencies {
24+
// sample java compile dependency. Remove if not required
25+
compile 'com.marklogic:marklogic-xcc:9.0.4'
26+
27+
//sample mlcp dependency. Remove if not required
28+
mlcp "com.marklogic:mlcp:9.0.5"
29+
}
30+
31+
/**
32+
* START: Disconnected gradle tasks
33+
*/
34+
gradle.taskGraph.whenReady { graph ->
35+
if (graph.hasTask(downloadToProjectMavenRepo)) {
36+
println project.gradle.gradleUserHomeDir
37+
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir, projectGradleHome))) {
38+
throw new GradleException("Please set the gradle user home property to $projectGradleHome on the gradle command line - e.g. \n " +
39+
(System.getProperty("os.name").startsWith("Windows") ? "" : "./") +
40+
"gradlew -Dgradle.user.home=$projectGradleHome <task_to_execute>")
41+
}
42+
}
43+
}
44+
45+
task downloadToProjectMavenRepo(type: Copy) {
46+
/*
47+
* Include any configuration dependencies here that you want to copy the dependencies for.
48+
* These are defined in the 'dependencies' block. E.g. you need to include
49+
* configurations.compile.files if you want your java 'compile' dependencies downloaded
50+
*/
51+
configurations.compile.files //includes 'java' compile dependencies. Remove if not needed
52+
configurations.mlcp.files //includes 'mlcp' dependencies. Remove if not needed
53+
54+
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1') // correct as of gradle 4.7
55+
into new File(rootDir, projectMavenRepo)
56+
eachFile {
57+
List<String> parts = it.path.split('/')
58+
it.path = (parts[0].replace('.', '/') + '/' + parts[1]) + '/' + parts[2] + '/' + parts[4]
59+
}
60+
includeEmptyDirs false
61+
}
62+
63+
task makeOfflineZip(type: Zip, dependsOn: downloadToProjectMavenRepo) {
64+
from rootDir
65+
excludes = ['.tmp', '.gradle', 'build/gradle-home', 'build/distributions', 'build/offline/gradle/wrapper/dists']
66+
destinationDir(file('build/distributions'))
67+
archiveName = 'offline.zip'
68+
doLast {
69+
println "Created offline project zip at build/distributions/offline.zip"
70+
}
71+
}
72+
73+
/**
74+
* END: Disconnected gradle tasks
75+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
projectMavenRepo=build/offline/maven-repo
2+
# if you change this, you need to modify gradlew and gradlew.bat also
3+
projectGradleHome=build/gradle-home
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=PROJECT
2+
distributionPath=build/offline/gradle/wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
4+
zipStoreBase=PROJECT
5+
zipStorePath=build/offline/gradle/wrapper
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#!/usr/bin/env sh
2+
3+
##############################################################################
4+
##
5+
## Gradle start up script for UN*X
6+
##
7+
##############################################################################
8+
9+
# Attempt to set APP_HOME
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ] ; do
14+
ls=`ls -ld "$PRG"`
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=`dirname "$PRG"`"/$link"
20+
fi
21+
done
22+
SAVED="`pwd`"
23+
cd "`dirname \"$PRG\"`/" >/dev/null
24+
APP_HOME="`pwd -P`"
25+
cd "$SAVED" >/dev/null
26+
27+
APP_NAME="Gradle"
28+
APP_BASE_NAME=`basename "$0"`
29+
# Set the gradle home to be a local project directorys
30+
GRADLE_USER_HOME="$APP_HOME/build/gradle-home"
31+
echo "Setting the GRADLE_USER_HOME to $GRADLE_USER_HOME \n(needed for the creation of the offline repository)\n"
32+
33+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
34+
DEFAULT_JVM_OPTS=""
35+
36+
# Use the maximum available, or set MAX_FD != -1 to use that value.
37+
MAX_FD="maximum"
38+
39+
warn () {
40+
echo "$*"
41+
}
42+
43+
die () {
44+
echo
45+
echo "$*"
46+
echo
47+
exit 1
48+
}
49+
50+
# OS specific support (must be 'true' or 'false').
51+
cygwin=false
52+
msys=false
53+
darwin=false
54+
nonstop=false
55+
case "`uname`" in
56+
CYGWIN* )
57+
cygwin=true
58+
;;
59+
Darwin* )
60+
darwin=true
61+
;;
62+
MINGW* )
63+
msys=true
64+
;;
65+
NONSTOP* )
66+
nonstop=true
67+
;;
68+
esac
69+
70+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
71+
72+
# Determine the Java command to use to start the JVM.
73+
if [ -n "$JAVA_HOME" ] ; then
74+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
75+
# IBM's JDK on AIX uses strange locations for the executables
76+
JAVACMD="$JAVA_HOME/jre/sh/java"
77+
else
78+
JAVACMD="$JAVA_HOME/bin/java"
79+
fi
80+
if [ ! -x "$JAVACMD" ] ; then
81+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
82+
83+
Please set the JAVA_HOME variable in your environment to match the
84+
location of your Java installation."
85+
fi
86+
else
87+
JAVACMD="java"
88+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
89+
90+
Please set the JAVA_HOME variable in your environment to match the
91+
location of your Java installation."
92+
fi
93+
94+
# Increase the maximum file descriptors if we can.
95+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
96+
MAX_FD_LIMIT=`ulimit -H -n`
97+
if [ $? -eq 0 ] ; then
98+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
99+
MAX_FD="$MAX_FD_LIMIT"
100+
fi
101+
ulimit -n $MAX_FD
102+
if [ $? -ne 0 ] ; then
103+
warn "Could not set maximum file descriptor limit: $MAX_FD"
104+
fi
105+
else
106+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
107+
fi
108+
fi
109+
110+
# For Darwin, add options to specify how the application appears in the dock
111+
if $darwin; then
112+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
113+
fi
114+
115+
# For Cygwin, switch paths to Windows format before running java
116+
if $cygwin ; then
117+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
118+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
119+
JAVACMD=`cygpath --unix "$JAVACMD"`
120+
121+
# We build the pattern for arguments to be converted via cygpath
122+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
123+
SEP=""
124+
for dir in $ROOTDIRSRAW ; do
125+
ROOTDIRS="$ROOTDIRS$SEP$dir"
126+
SEP="|"
127+
done
128+
OURCYGPATTERN="(^($ROOTDIRS))"
129+
# Add a user-defined pattern to the cygpath arguments
130+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
131+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
132+
fi
133+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
134+
i=0
135+
for arg in "$@" ; do
136+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
137+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
138+
139+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
140+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
141+
else
142+
eval `echo args$i`="\"$arg\""
143+
fi
144+
i=$((i+1))
145+
done
146+
case $i in
147+
(0) set -- ;;
148+
(1) set -- "$args0" ;;
149+
(2) set -- "$args0" "$args1" ;;
150+
(3) set -- "$args0" "$args1" "$args2" ;;
151+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
152+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
153+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
154+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
155+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
156+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
157+
esac
158+
fi
159+
160+
# Escape application args
161+
save () {
162+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
163+
echo " "
164+
}
165+
APP_ARGS=$(save "$@")
166+
167+
# Collect all arguments for the java command, following the shell quoting and substitution rules
168+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" "\"-Dgradle.user.home=$GRADLE_USER_HOME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
169+
170+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
171+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
172+
cd "$(dirname "$0")"
173+
fi
174+
175+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)