Skip to content

Instantly share code, notes, and snippets.

@davidmankin
Forked from mrdon/wksp.sh
Last active April 29, 2016 19:43
Show Gist options
  • Save davidmankin/df880081a17516a574bb774a3b6d867f to your computer and use it in GitHub Desktop.
Save davidmankin/df880081a17516a574bb774a3b6d867f to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# This script creates a parent pom for all listed modules, allowing you to open them up in IDEA
# in one go and have IDEA automatically link up dependencies
if [[ $1 == --help || $# < 2 ]]; then
echo "Usage: wksp.sh WORKSPACE_NAME MODULE_NAME..."
echo
echo "This command is meant to be run from the root directory for all projects"
exit 1
fi
base=$(pwd)
# Use the _name-workspace pattern to ensure the module is the first one in IDEA
wsName="_$1-workspace"
# Get rid of the workspace name so it isn't mistaken for a module later on
shift
wsDir="$base/.maven-workspace/$wsName"
if [ ! -d $wsDir ]; then
mkdir -p $wsDir
fi
wsPom="$wsDir/pom.xml"
echo >$wsPom "<project
xmlns=\"http://maven.apache.org/POM/4.0.0\"
xlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
<modelVersion>4.0.0</modelVersion>
<groupId>maven-workspace</groupId>
<artifactId>$wsName</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>"
for rawModuleName in "$@"; do
# Strip any trailing /
moduleName=${rawModuleName%/}
echo >>$wsPom " <module>../../$moduleName</module>"
done
echo >>$wsPom " </modules>
</project>"
echo "Workspace created at $wsPom"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment