Friday, May 20, 2016

Kickstarting a Java program

Here are steps to create a new Java command-line program.  Use a different quick start if you are making a web server as there are guides for those.

0. Prerequisite: Install Gradle.

1. Create an empty folder, we will refer to as project1.

2. Copy this build.gradle code into a new build.gradle file in your project1 folder.

(Modified from https://docs.gradle.org/current/userguide/tutorial_java_projects.html )

apply plugin: 'java'apply plugin: 'idea'
sourceCompatibility = 1.8version = '0.1'jar {
    manifest {
        attributes 'Implementation-Title': 'War Game',
                   'Implementation-Version': version
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'commons-collections',
    name: 'commons-collections',
    version: '3.2.2'    
    testCompile group: 'junit'
    name: 'junit', version: '4.+'}

test {
    systemProperties 'property': 'value'}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'       }
    }
}


3. At terminal, run
gradle wrapper
This will create a gradlew file for you.


4. At terminal, run
gradlew idea
Assuming using idea.

5. Open in idea

6. In IDEA, create this folder structure: src->main->java->project1

7. Right-click on the "java", mark as sources root.

8. Same thing for tests: src->test->java, mark java as test sources root.