Skip to content

Instantly share code, notes, and snippets.

@saltnlight5
Created October 31, 2012 17:15
Show Gist options
  • Save saltnlight5/3988407 to your computer and use it in GitHub Desktop.
Save saltnlight5/3988407 to your computer and use it in GitHub Desktop.
mkgradleproject.sh
PROJ=java-demo
if [[ $# -ge 1 ]]; then PROJ=$1; fi
echo "Creating $PROJ project."
if [[ -e $PROJ ]]; then
echo "ERROR: $PROJ already exists."
exit 1
fi
# Create a java project with Gradle build script.
mkdir -p $PROJ/src/main/java
echo "apply plugin: 'java'" > $PROJ/build.gradle
cd $PROJ
# # Add Maven central repository
# cat <<'EOM' >> build.gradle
# repositories { mavenCentral() }
# dependencies {
# testCompile('junit:junit:4.10')
# }
# EOM
# Add local dirs dependencies (Using Gradle's lib)
mkdir lib
cat <<'EOM' >> build.gradle
dependencies {
testCompile(
fileTree(dir: "${gradle.gradleHomeDir}/lib", include: '**/*.jar'),
fileTree(dir: 'lib', include: '**/*.jar')
)
}
EOM
# Add eclipse support
cat <<'EOM' >> build.gradle
apply plugin: 'eclipse'
eclipse.classpath.defaultOutputDir = new File(buildDir, 'eclipse-output')
EOM
## Add eclipse support
#cat <<'EOM' >> build.gradle
#
#apply plugin: 'application'
#mainClassName = 'deng.ServiceRunner'
#EOM
# Add a hello sample
cat <<'EOM' > src/main/java/Hello.java
public class Hello {
public void main(String[] args) {
System.out.println("Hello");
}
}
EOM
# Add a unit test sample
mkdir -p src/test/java
cat <<'EOM' > src/test/java/HelloTest.java
import org.junit.*;
import org.hamcrest.*;
public class HelloTest {
@Test public void testMe() {
Assert.assertThat("AB", CoreMatchers.is("A" + "B"));
}
}
EOM
# Test it out
gradle test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment