2017-05-26 10 views
0

私はGradleライフサイクルについて基本的な質問をしています。私のプロジェクトはマルチモジュールプロジェクトです。グラデーションタスクとグラデーションライフサイクルの連鎖

私は、次のコマンド気づい:

./gradlew clean bignibou-server:run 

は、次の2つのコマンドは、その順序で実行する実行するのと同じではありません。

./gradlew clean 

./gradlew bignibou-server:run 

bignibou-serverは私のモジュールの一つです。

最初のコマンドの出力結果は、以下の2つのコマンドとは異なる出力になります。

誰かが関連文書を指している可能性がある理由を説明してもらえますか?

edit:最初のケースでは、生成されたソース出力の1つが削除されますが、2番目のケースでは削除されません。どうすればいいの?

編集2:ルートbuild.gradleから

import io.franzbecker.gradle.lombok.task.DelombokTask 

def javaVersion = 1.8 

buildscript { 

    repositories { 
     mavenCentral() 
     maven { url "http://repo.spring.io/release" } 
     maven { url "http://repo.spring.io/milestone" } 
     maven { url "http://repo.spring.io/snapshot" } 
     maven { url "https://plugins.gradle.org/m2/" } 
    } 

    ext { 
     javaLanguageLevel = '1.8' 
    } 

    ext['mockito.version'] = "${mockitoVersion}" 
    ext['hibernate.version'] = "${hibernateVersion}" 

    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
     classpath("io.franzbecker:gradle-lombok:${gradleLombokVersion}") 
    } 
} 

configure(allprojects) { project -> 
    group = "com.bignibou" 

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

    configurations { 
     mapstruct 
    } 

    repositories { 
     mavenCentral() 
     maven { url "http://repo.spring.io/release" } 
     maven { url "http://repo.spring.io/milestone" } 
     maven { url "http://repo.spring.io/snapshot" } 
     maven { url "https://artifacts.elastic.co/maven" } 
    } 

    compileJava { 
     sourceCompatibility = javaVersion 
     targetCompatibility = javaVersion 
    } 

    test { 
     reports.html.destination = file("$reports.html.destination/unit") 
     reports.junitXml.destination = file("$reports.junitXml.destination/unit") 
    } 

    task delombok(type: DelombokTask) { 
     ext.outputDir = file("$buildDir/src-delomboked/java") 
     outputs.dir(outputDir) 
     sourceSets.main.java.srcDirs.each { 
      inputs.dir(it) 
      args(it, "-d", outputDir) 
     } 
    } 

    // FIXME: refactor paths to generated sources 
    task mapStructClean { 
     delete file("build/generated-sources/mapstruct/main") 
    } 

    task generateMainMapperClasses(type: JavaCompile, group: 'build') { 
     ext.aptDumpDir = file("${buildDir}/tmp/apt/mapstruct") 
     destinationDir = aptDumpDir 

     classpath = compileJava.classpath + configurations.mapstruct 
     source = file("$buildDir/src-delomboked/java") 
     ext.sourceDestDir = file("build/generated-sources/mapstruct/main") 

     options.define(
       compilerArgs: [ 
         "-nowarn", 
         "-proc:only", 
         "-encoding", "UTF-8", 
         "-processor", "org.mapstruct.ap.MappingProcessor" + ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor', 
         "-s", sourceDestDir.absolutePath, 
         "-source", rootProject.javaLanguageLevel, 
         "-target", rootProject.javaLanguageLevel, 
       ] 
     ); 

     inputs.dir source 
     outputs.dir "${buildDir}/generated-sources/mapstruct/main" 
     doFirst { 
      sourceDestDir.mkdirs() 
     } 
     doLast { 
      aptDumpDir.delete() 
     } 
    } 
} 

task wrapper(type: Wrapper) { gradleVersion = '3.5' } 

からbignibou-commmonモジュール:

description = "Bignibou Common" 

apply plugin: 'org.springframework.boot' 
apply plugin: 'io.franzbecker.gradle-lombok' 

configurations { 
    querydslapt 
    mapstruct 
} 


dependencyManagement { 
    dependencies { 
     dependency "org.elasticsearch:elasticsearch:${elasticsearchVersion}" 
    } 
} 

dependencies { 

    compile("org.springframework.boot:spring-boot-starter-data-jpa") { 
     exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc' 
    } 
    compile("org.springframework.boot:spring-boot-starter-mail") 
    compile('org.springframework.security:spring-security-core') 
    compile('org.hibernate:hibernate-validator') 
    compile("org.hibernate:hibernate-java8") 
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") 

    //Spring cloud 
    compile("org.springframework.cloud:spring-cloud-spring-service-connector") 
    compile("org.springframework.cloud:spring-cloud-localconfig-connector") 
    compile("org.springframework.cloud:spring-cloud-cloudfoundry-connector") 

    // Relational Database 
    compile("org.postgresql:postgresql:${postgresqlVersion}") 
    compile("org.flywaydb:flyway-core") 

    // Connection pooling 
    compile("com.zaxxer:HikariCP") 

    //Shield 
    compile("org.elasticsearch.client:x-pack-transport:${elasticsearchVersion}") 
    compile("org.elasticsearch:elasticsearch:${elasticsearchVersion}") 
    compile("org.apache.logging.log4j:log4j-api") 
    compile("org.apache.logging.log4j:log4j-core") 

    // QueryDSL 
    compile("com.querydsl:querydsl-core:${queryDslVersion}") 
    compile("com.querydsl:querydsl-jpa:${queryDslVersion}") 
    querydslapt("com.querydsl:querydsl-apt:${queryDslVersion}") 

    // Jackson 
    compile("com.fasterxml.jackson.core:jackson-core") 
    compile("com.fasterxml.jackson.core:jackson-annotations") 

    compile("org.mapstruct:mapstruct-jdk8:${mapstructVersion}") 
    mapstruct("org.mapstruct:mapstruct-processor:${mapstructVersion}") 
    compile("org.apache.httpcomponents:httpclient:${httpClientVersion}") 

    compile("org.jasypt:jasypt:${jasyptVersion}") 

} 

sourceSets { 

    main { 
     ext.originalJavaSrcDirs = java.srcDirs 
     java.srcDir "build/generated-sources/mapstruct/main" 
     output.dir("build/generated-mail-templates") 
    } 

    generated { 
     java { 
      srcDirs = ["build/generated-sources/java", "build/src-delomboked/java", "build/generated-sources/mapstruct/main"] 
     } 
    } 
} 

bootRepackage { 
    enabled = false 
} 

task generateQueryDSL(type: JavaCompile, group: 'build') { 
    description "Generates the QueryDSL query types" 
    source = sourceSets.main.java 
    classpath = configurations.compile + configurations.querydslapt 
    options.compilerArgs = [ 
      "-proc:only", 
      "-processor", 
      "com.querydsl.apt.jpa.JPAAnnotationProcessor" + ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor' 
    ] 
    destinationDir = sourceSets.generated.java.srcDirs.iterator().next() 
} 

// FIXME: add cssFile & 
// FIXME: add dependsOn processMailTemplates & 
// FIXME: clean mail templates html 
// FIXME: ensure build is stopped if templates are not processed 

task npmInstall(type: Exec) { 
    description "npm install" 
    commandLine 'npm', 'install' 
} 

task processMailTemplates { 
    description "Processes mail templates" 
    dependsOn npmInstall 

    def templateSrcDir = "src/main/templates/mail/" 
    def templateDestDir = "build/generated-mail-templates/META-INF/templates/mail/" 

    mkdir templateDestDir 

    def templateNames = [] 

    fileTree(dir: templateSrcDir, include: '**/*.html').visit { 
     FileVisitDetails details -> templateNames << details.file.name 
    } 

    templateNames.each { templateName -> inlineCss(templateSrcDir + templateName, templateDestDir + templateName) } 

    outputs.upToDateWhen { false } 
} 

static def inlineCss(src, dest) { 
    def juice = 'node_modules/.bin/juice' 
    def juiceResourcesDir = 'src/main/templates/misc/' 
    def juiceArgs = "--options-file ${juiceResourcesDir}juiceOptions.json --css ${juiceResourcesDir}mailStyle.css" 
    "${juice} ${juiceArgs} ${src} ${dest}".execute(null, new File('bignibou-common')) 
} 


compileJava { 
    dependsOn generateQueryDSL 
    source generateQueryDSL.destinationDir 
} 

compileGeneratedJava { 
    dependsOn generateQueryDSL 
    options.warnings = false 
    classpath += sourceSets.main.runtimeClasspath 
} 

idea { 
    module { 
     sourceDirs += file('build/generated-sources/java') 
    } 
} 

processResources.dependsOn processMailTemplates 
compileJava.dependsOn generateMainMapperClasses 
generateMainMapperClasses.dependsOn mapStructClean 
generateMainMapperClasses.dependsOn delombok 


clean { 
    delete sourceSets.generated.java.srcDirs 
} 

からbignibou-serverモジュール:

description = "Bignibou Server" 

configurations { 
    mapstruct 
    integrationTest 
    integrationTestCompile.extendsFrom testCompile 
    integrationTestRuntime.extendsFrom testRuntime 
} 

apply plugin: 'io.franzbecker.gradle-lombok' 
apply plugin: 'org.springframework.boot' 
apply plugin: 'application' 


dependencyManagement { 
    dependencies { 
     dependency "org.elasticsearch:elasticsearch:${elasticsearchVersion}" 
    } 
} 

dependencies { 
    compile project(":bignibou-common") 
    compile project(":bignibou-client") 

    //Spring boot 
    compile("org.springframework.boot:spring-boot-starter-actuator") 
    compile("org.springframework.boot:spring-boot-starter-data-jpa") { 
     exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc' 
    } 
    compile("org.springframework.boot:spring-boot-starter-data-redis") { 
     exclude group: 'redis.clients', module: 'jedis' 
    } 
    compile("biz.paluch.redis:lettuce:${lettuceVersion}") 
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-security") 
    compile("org.springframework.boot:spring-boot-starter-thymeleaf") 
    compile("org.springframework.boot:spring-boot-starter-cache") 

    // Miscellaneous 
    compile("commons-collections:commons-collections") 
    compile("org.apache.commons:commons-lang3:${commonLangVersion}") 
    mapstruct("org.mapstruct:mapstruct-processor:${mapstructVersion}") 

    //Caching 
    compile("org.hibernate:hibernate-ehcache") 
    compile("com.github.ben-manes.caffeine:caffeine:${caffeineVersion}") 

    // Spring Session 
    compile("org.springframework.session:spring-session") 

    // Testing 
    testCompile project(":bignibou-test") 
} 

run { 
    systemProperty "spring.cloud.propertiesFile", System.getProperty("user.dir") + "/spring-cloud.properties" 
} 

springBoot { 
    mainClassName = "com.bignibou.Application" 
} 

sourceSets { 

    main { 
     ext.originalJavaSrcDirs = java.srcDirs 
     java.srcDir "build/generated-sources/mapstruct/main" 
    } 

    generated { 
     java { 
      srcDirs = ["build/src-delomboked/java", "build/generated-sources/mapstruct/main"] 
     } 
    } 

    integrationTest { 
     java.srcDirs = ['src/it/java'] 
     resources.srcDirs = ['src/it/resources', 'src/main/resources'] 
     compileClasspath = sourceSets.main.output + configurations.testRuntime 
     runtimeClasspath = output + compileClasspath 
    } 
} 

task integrationTest(type: Test) { 
    description "Run the integration tests." 
    testClassesDir = sourceSets.integrationTest.output.classesDir 
    classpath = sourceSets.integrationTest.runtimeClasspath 
    reports.html.destination = file("$reports.html.destination/integration") 
    reports.junitXml.destination = file("$reports.junitXml.destination/integration") 
} 

compileJava.dependsOn generateMainMapperClasses 
generateMainMapperClasses.dependsOn mapStructClean 
generateMainMapperClasses.dependsOn delombok 

check.dependsOn integrationTest 
integrationTest.shouldRunAfter test 

編集3:最初のコマンドによってで削除されるフォルダではなく秒(bignibou-commonモジュールから)以下の通りです:

build/generated-mail-templates 

編集4:私はコメントアウトした後ということに気づきましたoutput.dir(...コール(下記参照)、build/generated-mail-templatesが削除されませんが、残念ながらテンプレートがクラスパスに含まれていません...

sourceSets { 
     main { 
     ext.originalJavaSrcDirs = java.srcDirs 
     java.srcDir "build/generated-sources/mapstruct/main" 
     //output.dir("build/generated-mail-templates") 
     } 
+0

ビルドのコードと2つのケースで得られる出力を投稿した場合、説明しやすくなるかもしれません。 –

+0

@JBNizet私は最初の編集で自分の投稿を編集しました。 2回目の編集でビルドスクリプトの一部を含めます。 – balteo

+0

@JBNizet私はそれに応じて自分の投稿を編集しました。 – balteo

答えて

2
task processMailTemplates { 
    description "Processes mail templates" 
    dependsOn npmInstall 

    def templateSrcDir = "src/main/templates/mail/" 
    def templateDestDir = "build/generated-mail-templates/META-INF/templates/mail/" 

    mkdir templateDestDir 

    def templateNames = [] 

    fileTree(dir: templateSrcDir, include: '**/*.html').visit { 
     FileVisitDetails details -> templateNames << details.file.name 
    } 

    templateNames.each { templateName -> inlineCss(templateSrcDir + templateName, templateDestDir + templateName) } 

    outputs.upToDateWhen { false } 
} 

このすべてのコードは、実行するためにgradleに依頼するタスクに関係なく、設定フェーズで実行されます。代わりに、実行フェーズで実行する必要があります。

task processMailTemplates { 
    description "Processes mail templates" 
    dependsOn npmInstall 

    outputs.upToDateWhen { false } 

    doLast { 
     def templateSrcDir = "src/main/templates/mail/" 
     def templateDestDir = "build/generated-mail-templates/META-INF/templates/mail/" 

     mkdir templateDestDir 

     def templateNames = [] 

     fileTree(dir: templateSrcDir, include: '**/*.html').visit { 
      FileVisitDetails details -> templateNames << details.file.name 
     } 

     templateNames.each { templateName -> inlineCss(templateSrcDir + templateName, templateDestDir + templateName) } 
    } 
} 
+0

ありがとうございます。私は構成フェーズと実行フェーズの違いを認識していませんでした。私はアドバイスされたように私の仕事の定義を変更しましたが、上記の行動の相違は残っています。あなたはそれがなぜ他のアイデアを持っていますか?なぜでしょうか。 – balteo

+0

本当にありません。私はあなたがmapStructCleanで同じミスをしていることに気づいていますが、それがあなたの問題の理由だとは思わない。 –