gradle自己没有类似maven archtype那样的根据原型初始化新的工程目录结构,这里写了一个task用来创建maven风格的目录结构 build.gradle
文件:
apply plugin: ‘java‘
apply plugin: ‘groovy‘
group = "com.ma"
version = "1.0"
ext{
// java文件编码方式设置为utf-8
compileJava.options.encoding = ‘UTF-8‘
compileTestJava.options.encoding = ‘UTF-8‘
sourceCompatibility = 1.6
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile(
"commons-httpclient:commons-httpclient:3.1",
"org.codehaus.groovy:groovy-all:2.3.6",
files(‘d:/jar/asprise-ocr-java-5/aocr.jar‘)
)
}
task run(type: JavaExec, dependsOn: ‘classes‘) {
description ‘运行指定main函数的java‘
classpath = sourceSets.main.runtimeClasspath
if(project.hasProperty(‘main‘)){
main = "com.ma.${project.getProperty(‘main‘)}"
}
}
task init << {
description ‘初始化工程目录‘
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}
gradle run -Pmain=Test
运行Test.java的main函数 gradle init
创建maven工程目录结构
时间: 2024-10-10 09:31:26