2015年3月2日 星期一

Gradle Build Project Example

  • Build.gradle : Simple Java Project Example

apply plugin: 'java'
sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src'
        }
    }
}
repositories {
    maven {
        credentials {
            username 'deployment'
            password ''
        }
        url "http://127.0.0.1:8081/nexus/content/groups/public/"
    }
}
 
dependencies {
    compile 'junit:junit:4.11'
    …
    …
}

  • Build.gradle : Web Project Example

apply plugin: 'eclipse-wtp'
apply plugin: 'jetty'

  • Build.gradle : Application Project Example

apply plugin: 'application'

def createScript(project, mainClass, name) {
  project.tasks.create(name: name, type: CreateStartScripts) {
    outputDir       = new File(project.buildDir, 'scripts')
    mainClassName   = mainClass
    applicationName = name
    classpath       = project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime
}

project.tasks[name].dependsOn(project.jar)

  project.applicationDistribution.with {
    into("bin") {
      from(project.tasks[name])
      fileMode = 0755
    }
  }
  
project.tasks[name].doLast {
    unixScript.text = unixScript.text.replace("\$CLASSPATH", ".:\$APP_HOME/lib/*") 
    //windowsScript.text = windowsScript.text.replace("%CLASSPATH%", ".;%APP_HOME%\\lib\\*") 
}
}

startScripts.enabled = false
run.enabled = false

createScript(project, 'com.gigabyte.HelloWorld ', 'helloworld')

沒有留言:

張貼留言