一個簡單的Gradle項目

記錄下作的過程,這是一個簡單的Gradle項目,主要用來測試一些日誌的寫法,日誌的輸出等等。java

建立項目

建立項目大概是下面這些步驟:git

  1. 建立一個目錄(test),並執行git init置於git管理下。web

  2. 在目錄test下建立build.gradle文件。spring

  3. build.gradle中添加apply plugin: 'java',這會添加一些定製的java tasks。api

  4. 添加依賴的maven倉庫app

    repositories {
        mavenLocal()
        maven{ url 'http://localhost:8081/artifactory/libs-release/'}
    }
  5. 添加依賴示例:eclipse

    dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
        testCompile group: 'junit', name: 'junit', version: '4.+'
    }
  6. 定製項目,添加屬性:version = '1.0'maven

  7. 配置發佈文件到本地目錄,學習

    uploadArchives {
        repositories {
           flatDir {
               dirs 'repos'
           }
        }
    }
  8. 添加apply plugin: 'eclipse'用來生成eclipse項目文件。測試

  9. 可使用命令gradle -q dependencies web:dependencies查看項目的全部依賴信息。

  10. 能夠自定義項目屬性,

    ext {
        slf4jVersion = '1.7.21'
    }
  11. 使用項目屬性"org.slf4j:slf4j-api:${slf4jVersion}"

  12. 能夠過濾項目的依賴信息gradle -q dependencies --configuration compile,查看依賴能夠清晰的看到依賴的傳遞過程.

  13. 可使用exclude排除指定的依賴

    compile ("org.slf4j:slf4j-log4j12:${slf4jVersion}"){
        exclude module:"log4j"
        exclude module:"slf4j-api"
    }
  14. 終於把springframework構建完成了,命令:gradle build -x test -x javadoc --info

SLF4J 使用手冊

主要是學習下,大概是抄了下文檔。SLF4J使用手冊中文版

相關文章
相關標籤/搜索