Intellij idea开发工具来开发Java工程的时候,通常会使用ant、maven、groovy、gradle等工具来管理项目依赖。我在工程中使用了较新的gradle作为管理工具。但是在运行build.gradle的build任务时,通常需要将多个目录设置为源代码文件目录。否则一旦build完了以后,某些目录中的源代码会被忽视,而认为不是源代码。
src/main/thrift-java 也希望成为gradle可识别的源文件目录
// # build.gradle #
buildscript {
repositories {
maven {
url "http://repo.maven.apache.org/maven2/"
}
mavenCentral()
}
dependencies {
classpath group: ‘co.tomlee.gradle.plugins‘, name: ‘gradle-thrift-plugin‘, version: ‘0.0.6‘
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.10.RELEASE")
}
}
apply plugin: ‘java‘
apply plugin: ‘idea‘
apply plugin: ‘thrift‘
apply plugin: ‘spring-boot‘
apply plugin: ‘war‘
sourceCompatibility = 1.7
version = ‘1.0‘
repositories {
mavenCentral()
}
dependencies {
compile ‘org.apache.thrift:libthrift:0.9.2‘
compile ‘org.springframework:spring-orm:4.1.4.RELEASE‘
compile(‘org.springframework.boot:spring-boot-starter-web:1.2.1.RELEASE‘)
compile(‘org.springframework.boot:spring-boot-starter-data-jpa:1.2.2.RELEASE‘)
//compile(‘org.springframework.boot:spring-boot-starter-actuator:1.2.2.RELEASE‘)
compile(‘org.springframework:spring-jdbc:4.1.5.RELEASE‘)
//compile(‘com.h2database:h2:1.4.185‘)
// mysql
compile(‘mysql:mysql-connector-java:5.1.34‘)
// hibernate
compile(‘org.hibernate:hibernate-entitymanager:4.3.8.Final‘)
compile(‘org.projectreactor.spring:reactor-spring-context:1.1.3.RELEASE‘)
compile(‘org.springframework:spring-web:4.1.5.RELEASE‘)
compile(‘org.springframework.amqp:spring-rabbit:1.4.2.RELEASE‘)
compile(‘org.springframework.amqp:spring-amqp:1.4.2.RELEASE‘)
compile group: ‘org.springframework.data‘, name: ‘spring-data-mongodb‘, version: ‘1.6.1.RELEASE‘
compile "org.springframework.data:spring-data-rest-webmvc:2.2.1.RELEASE"
compile("com.fasterxml.jackson.core:jackson-databind:2.5.0")
compile("com.fasterxml.jackson.core:jackson-annotations:2.5.0")
compile("com.fasterxml.jackson.core:jackson-core:2.5.0")
//compile group: ‘org.hibernate‘, name: ‘hibernate-core‘, version: ‘4.3.7.Final‘
compile(‘org.springframework:spring-test:4.1.5.RELEASE‘)
testCompile group: ‘junit‘, name: ‘junit‘, version: ‘4.11‘
}
generateThriftSource {
//
// The output directory (optional)
//
out file(‘src/main/thrift-java‘)
verbose false
debug false
strict true
//
// Modify the include path (optional)
//
// path file(‘vendor/thrift‘)
//
// Set the thrift executable (optional)
//
executable ‘C:\\Program Files (x86)\\Java\\jdk1.7.0_40\\bin\\thrift.exe‘
generators {
//
// --gen java:hashcode,beans
//
java {
//
// Options passed to the `java` generator
//
option ‘hashcode‘
option ‘beans‘
}
}
}
// here demonstrates how to add multiple srcDirs into project
sourceSets {
main {
java {
srcDirs = [‘src/main/java‘, ‘src/main/thrift-java‘]
}
resources {
srcDirs = [‘src/main/resources‘]
}
}
test {
java {
srcDirs = [‘src/test/java‘, ‘src/test/thrift‘]
}
resources {
srcDirs = [‘src/test/resources‘]
}
}
}
jar {
// set the main class entry for the executable jar
manifest {
attributes ‘Main-Class‘: ‘calculator.CalculatorClient‘,
‘Implementation-Title‘: ‘Gradle quickStart‘
}
// this will add all the dependent jars into the generated-jar package
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
原文地址:http://blog.csdn.net/nisxiya/article/details/44151555