Intellij idea中gradle设置多源文件目录

问题描述

Intellij idea开发工具来开发Java工程的时候,通常会使用ant、maven、groovy、gradle等工具来管理项目依赖。我在工程中使用了较新的gradle作为管理工具。但是在运行build.gradle的build任务时,通常需要将多个目录设置为源代码文件目录。否则一旦build完了以后,某些目录中的源代码会被忽视,而认为不是源代码。

目标

  • src/main/java 为默认的源文件目录
  • src/main/thrift 也希望成为gradle可识别的源文件目录
  • 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)
        }
    }
}
时间: 2024-08-07 04:33:24

Intellij idea中gradle设置多源文件目录的相关文章

intellij idea中gradle工程使用git进行版本控制

1.创建git远程库,并复制git库地址 2.clone库到本地 3.增加代码到angularjs_web工程中 4.右击工程,准备提交代码,发现无git选项,vcs中也不能提交工程, 这时,应该导入版本控制,创建repository,选中刚刚的angularjs_web的当前工程,然后会发现文件名变红色了: 此时右击工程/git/add 文件名会变绿, 然后右击工程/git/commit directory提交代码 工程中无.git文件和目录, 右击工程目录中空白地方调用git bash,粘贴

在intellij IDEA中为web应用创建图片虚拟目录(详细截图)

在intellij IDEA中为web应用创建图片虚拟目录(详细截图) 在intellij IDEA中为web应用创建图片虚拟目录详细截图 工程配置和环境 操作步骤 在非IDE环境下配置虚拟目录 本文主要展示如何在intellij IDEA中为web应用添加虚拟目录映射,并附上步骤截图 工程配置和环境 我使用的版本为 tomcat 8.0.30 intellij 15.0.2 jdk 1.8.0_25 已经部署好了一个web应用,并且已经在IDEA中添加好了tomcat容器,现在想为这个web应

在Adobe AIR/AS 程序中 如何设置目录

首先所有目录都以 "File:///"开头,无论Mac或者Windows 后面的路径 Windows: E:/WorkGround/Txt.txt  --> "File:///E:/WorkGround/Txt.txt" Mac: /User/eran/Documents/Txt.txt   --> "File:////User/eran/Documents/Txt.txt" // -configPath File:///E:/Wor

Linux中如何设置目录或文件的归属及权限

我们首先来查看一下目录的权限及归属,各个字段表示的含义: 权限字符在文件中的含义为: 读取.写入.执行权限也可以用数字来表示,具体如下: 命令chmod用来更改目录或文件的权限,基本的命令格式如下: chmod [ugoa] [+=-] [r w x] 文件或目录 或者 chmod nnn 文件或目录 其中ugoa表示该权限设置所针对的用户类别.u代表文件属主:g代表文件属组:o代表其他任何用户:a代表所有用户(u.g.o的总和). +=-表示设置权限的操作动作.+代表增加相应的权限:- 代表减

在 IntelliJ IDEA 中配置 JSF 开发环境的入门详解

JSF 作为 JavaEE 官方标准,在了解并掌握其基本开发技术后,对于功能要求较高.业务流程复杂的各种现代 Web 应用程序开发将会成为非常合适且强大的高效率开发利器.JSF 的开发环境搭建涉及到在 IntelliJ IDEA 中配置 Web Application Server.配置 JavaEE 基本环境.选择 JSF 相关功能模块等,之所以选择 IDEA 作为开发环境,是因为 IDEA 作为业界公认的最强 Java 集成开发环境,已逐渐成为事实上的 Java 及相关应用开发环境标准,甚至

IOS中获取各个文件的目录路径的方法和NSFileManager类

转自:http://blog.sina.com.cn/s/blog_5fb39f910101di92.html IOS中获取各种文件的目录路径的方法 iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory()), 手动保存的文件在documents文件里 Nsuserdefaults保存的文件在tmp文件夹里 1.Documents 目录:您应该将所有

IOS中获取各种文件的目录路径的方法

iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory()), 手动保存的文件在documents文件里 Nsuserdefaults保存的文件在tmp文件夹里 1.Documents 目录:您应该将所有de应用程序数据文件写入到这个目录下.这个目录用于存储用户数据或其它应该定期备份的信息. 2.AppName.app 目录:这是应用程序的程序包目录,

Intellij IDEA 13 基础设置

最近也想试一试这款自诩为"The Best Java IDE",但是由于从开始学Java就一直在使用Eclipse,不得不说,刚开始使用总觉得有点不对的地方,而当我平时使用的功能配置下来后发现,这款IDE给我的第一印象还算不错的. 首先是基本问题----Project和Modul,在IDEA中Project相当于Eclipse中的工作区,而Modul相当于Eclipse的Project.下面这个网址是对Eclipser的基本问题的回答,可参考: http://www.jetbrains

IDEA中Gradle插件的使用

Idea本身已经集成了Gradle插件,你可以在File | Settings | Build, Execution, Deployment | Build Tools | Gradle 下找到 相关配置 配置 本文基于IDEA 2016.2 配置项 说明 Linked Gradle projects 所有Gradle添加了Gradle支持的项目列表 | 项目相关配置 | 说明 | |----------------| | Use auto-import | 是否开启自动导入,若开启修改grad