Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Jun 21, 2018
2 parents d1660cb + aa14704 commit 4428c50
Show file tree
Hide file tree
Showing 24 changed files with 888 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.gradle
117 changes: 117 additions & 0 deletions examples/disconnected-project-using-plugins-and-gradlew/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Standalone Gradle deployer with ml-gradle

## Quickstart

Summary of the steps required. See sections below for more detailed steps

*NOTE:* The use of gradlew is required

1. Create standalone deployer zip
```
./gradlew makeOfflineZip
```
2. Copy zip (build/distributions/offline.zip) to desired location / server and unzip

3. Run disconnected tasks from unzip location
```
./gradlew mlDeploy -Pdisconnected=true
```


## Overview

An example of how to create a completely self-contained deployer zip that contains:

1. All of the plugin / dependencies required to run the deployment (including ml-gradle)
2. The Gradle distribution

Once the zip has been created, you only need Java to run the deployment tasks.

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.

## Requirements

* Java 8/9
* Internet connection (for creation of zip only)


## How it works

This project will:

* Download all of the required dependencies (including plugins) into the 'build/offline/maven-repo' directory in the project
* Download the Gradle binary distribution (zip) into the 'build/offline/gradle/wrapper' directory in the project
* Create an offline.zip in build/distributions that contains
* the Gradle project itself
* all of the required dependencies
* the Gradle distribution that works with the gradlew executable


## Usage

*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.

## 1. Create the self-contained deployer zip

*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

#### Linux / Mac

```
./gradlew makeOfflineZip
```

#### Windows

```
gradlew makeOfflineZip
```


## 2. Unzip the distribution

Copy the created offline.zip to the desired location and unzip

```
unzip offline.zip
```

## 3. Execute disconnected the Gradle tasks

From the directory that you have unzipped the offline.zip file into

```
./gradlew mlDeploy -Pdisconnected=true
```

This will use the jars that you have already downloaded to 'build/offline/maven-repo'

## Customise

**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.

E.g. (assuming you are using the Java plugin), the configuration below will download all the compile and runtime dependencies that you have defined:

```
task downloadToProjectMavenRepo(type: Copy) {
configurations.compile.files
configurations.runtime.files
...
```

## Use own gradle instance (rather than gradlew)

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

1. Remove build directory (to ensure that no gradlew zip exists in the build dir)

2. Create deployer zip
```
gradle -Dgradle.user.home=build/gradle-home makeOfflineZip
```
3. Copy zip (build/distributions/offline.zip) to desired location / server and unzip

4. Run disconnected tasks from unzip location
```
gradle mlDeploy -Pdisconnected=true
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
plugins {
id 'java' //optional - delete if not needed
id 'net.saliman.properties' version '1.4.6'
id 'com.marklogic.ml-gradle' version '3.7.1'
}

repositories {
// To use gradle in disconnected mode, you just need to set the 'disconnected' property. E.g. gradle compileJava -Pdisconnected
if (project.hasProperty("disconnected") && !"FALSE".equalsIgnoreCase(disconnected)) {
println "Using offline repositories"
maven { url uri(projectMavenRepo) }
} else {
println "Using online repositories"
jcenter()
maven { url "https://developer.marklogic.com/maven2/" }
}
}

configurations {
mlcp //example if you want to use mlcp. Delete otherwise
}

dependencies {
// sample java compile dependency. Remove if not required
compile 'com.marklogic:marklogic-xcc:9.0.4'

//sample mlcp dependency. Remove if not required
mlcp "com.marklogic:mlcp:9.0.5"
}

/**
* START: Disconnected gradle tasks
*/
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(downloadToProjectMavenRepo)) {
println project.gradle.gradleUserHomeDir
if (!project.gradle.gradleUserHomeDir.equals(new File(rootDir, projectGradleHome))) {
throw new GradleException("Please set the gradle user home property to $projectGradleHome on the gradle command line - e.g. \n " +
(System.getProperty("os.name").startsWith("Windows") ? "" : "./") +
"gradlew -Dgradle.user.home=$projectGradleHome <task_to_execute>")
}
}
}

task downloadToProjectMavenRepo(type: Copy) {
/*
* Include any configuration dependencies here that you want to copy the dependencies for.
* These are defined in the 'dependencies' block. E.g. you need to include
* configurations.compile.files if you want your java 'compile' dependencies downloaded
*/
configurations.compile.files //includes 'java' compile dependencies. Remove if not needed
configurations.mlcp.files //includes 'mlcp' dependencies. Remove if not needed

from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1') // correct as of gradle 4.7
into new File(rootDir, projectMavenRepo)
eachFile {
List<String> parts = it.path.split('/')
it.path = (parts[0].replace('.', '/') + '/' + parts[1]) + '/' + parts[2] + '/' + parts[4]
}
includeEmptyDirs false
}

task makeOfflineZip(type: Zip, dependsOn: downloadToProjectMavenRepo) {
from rootDir
excludes = ['.tmp', '.gradle', 'build/gradle-home', 'build/distributions', 'build/offline/gradle/wrapper/dists']
destinationDir(file('build/distributions'))
archiveName = 'offline.zip'
doLast {
println "Created offline project zip at build/distributions/offline.zip"
}
}

/**
* END: Disconnected gradle tasks
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
projectMavenRepo=build/offline/maven-repo
# if you change this, you need to modify gradlew and gradlew.bat also
projectGradleHome=build/gradle-home
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=PROJECT
distributionPath=build/offline/gradle/wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
zipStoreBase=PROJECT
zipStorePath=build/offline/gradle/wrapper
175 changes: 175 additions & 0 deletions examples/disconnected-project-using-plugins-and-gradlew/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Set the gradle home to be a local project directorys
GRADLE_USER_HOME="$APP_HOME/build/gradle-home"
echo "Setting the GRADLE_USER_HOME to $GRADLE_USER_HOME \n(needed for the creation of the offline repository)\n"

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
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"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 4428c50

Please sign in to comment.