Gradle Build stand alone project running jar files

1. Gradle 配置文件配置

build.gradle 

apply plugin: 'java'
apply plugin: 'eclipse'


sourceCompatibility = 1.7
version = '1.0.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                   'Implementation-Version': version
    }
}


repositories {
    mavenCentral()
   //  maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}


dependencies {
    //logback 
    compile 'org.slf4j:slf4j-api:1.7.12'
  compile 'org.slf4j:jcl-over-slf4j:1.7.12'
compile 'ch.qos.logback:logback-classic:1.1.3'

compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile 'org.apache.httpcomponents:httpclient-cache:4.5.3'

    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    compile fileTree(dir: 'libs', include: '*.jar')
    testCompile group: 'junit', name: 'junit', version: '4.+'
}


test {
    systemProperties 'property': 'value'
}






task constant {
ext.buildPath="/build/target/TestProject"
ext.targetBin=buildPath+"/bin"
ext.targetConf=buildPath+"/conf"
ext.targetLibs=buildPath+"/libs"
ext.targetLogs=buildPath+"/logs"

ext.testPath="/build/target/TestProject"

ext.devEvn="dev"
ext.uatEvn="uat"
ext.proEvn="pro"
ext.testEvn="test"
}
task variable {
ext.binPath="build/bin"
ext.confPath="build/resources/main"
ext.libPath="build/libs"
}


task cleanTarget(dependsOn:build) << {
delete constant.buildPath
file(constant.buildPath).mkdirs()
file(constant.targetBin).mkdirs()
file(constant.targetConf).mkdirs()
file(constant.targetLibs).mkdirs()
file(constant.targetLogs).mkdirs()
}


task copyResource(dependsOn:cleanTarget) << {
copy{
from configurations.runtime
into constant.targetLibs
}


copy{
from variable.binPath
into constant.targetBin
}
    
copy{
from variable.confPath
   into constant.targetConf
}

copy{
from variable.libPath
    into constant.targetLibs
}


}






task buildDev(dependsOn:[clean,copyResource]) << {
}


task buildUat(dependsOn:[clean,copyResource]) << {
}


task buildPro(dependsOn:[clean,copyResource]) << {
}




task copyJars(type: Copy) {
  from configurations.runtime
  into 'build/libs' 
}


test {
    systemProperties 'property': 'value'
}


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


2. 运行Gradle task, build 项目jar file

 cmd 命令运行



相应的jar files 生成


你可能感兴趣的:(Java,Gradle,gradle,Java,Jar)