1

I have one modular project, I decided to distribute it to modules. Server and client.

There was a question now. How to call a dependent task from another module?

parent build.gradle

plugins {
  id "net.ltgt.apt" version "0.14"
}

apply from: "$rootDir/gradle/idea.gradle"

group 'com.test.portal'
version '1.0-SNAPSHOT'

allprojects {
  apply plugin: 'net.ltgt.apt'
}

subprojects {
  apply from: "$rootDir/gradle/versions.gradle"
  apply from: "$rootDir/gradle/java.gradle"

  repositories {
    mavenCentral()
    mavenLocal()
    jcenter()
  }
}

java.gradle

def generatedDir = new File("$projectDir", "src/generated")

apply plugin: 'java'

sourceSets {
  generated {
    java.srcDir "src/generated/java"
  }
  main.java.srcDirs = ['src/main/java', "src/generated/java"]
  main.resources.srcDir "src/main/resources"
  test.java.srcDir "src/test/java"
  test.resources.srcDir "src/test/resources"
}

// deletes generated classes before new compilation
task deleteGenerated(type: Delete) {
  generatedDir.deleteDir()
}

compileGeneratedJava {
  dependsOn('deleteGenerated')
}

compileJava {
  sourceCompatibility = "1.8"
  targetCompatibility = "1.8"
  options.encoding = 'UTF-8'
  options.compilerArgs = ['-Xlint:unchecked'] // Just a smoke test that using this option does not lead to any
  options.annotationProcessorGeneratedSourcesDirectory = new File("$generatedDir", "java")
  dependsOn(processResources, compileGeneratedJava)
  source += sourceSets.generated.java
  source += sourceSets.generated.output
}

test {
  systemProperties = System.properties
}

And I have 2 child-modules

GWT

build.gradle

apply from: "$rootDir/gradle/gwt.gradle"

dependencies {
...
}

compileGwt {
  classpath {
    [
        sourceSets.main.java.srcDirs,           // Java source
        sourceSets.main.output.resourcesDir,    // Generated resources
        sourceSets.main.output.classesDir,      // Generated classes
        sourceSets.main.compileClasspath,       // Deps
    ]
  }
}

gwt.gradle

task compileGwt(dependsOn: classes, type: JavaExec) {
  ext.buildDir = "${project.buildDir}/gwt"
  ext.extraDir = "${project.buildDir}/extra"

  inputs.file sourceSets.main.java.srcDirs
  inputs.dir sourceSets.main.output.resourcesDir
  outputs.dir buildDir

  doFirst {
    file(buildDir).mkdirs()
  }

  main = "com.google.gwt.dev.Compiler"

  classpath {
    [
        sourceSets.main.java.srcDirs,           // Java source
        sourceSets.main.output.resourcesDir,    // Generated resources
        sourceSets.main.output.classesDir,      // Generated classes
        sourceSets.main.compileClasspath,       // Deps
    ]
  }

  if (project.hasProperty('dev')) {
    println "Run developer mode"
    args = [
        "com.test.portal.AppClientModule",
        "-war", buildDir,
        "-logLevel", "INFO",
        "-localWorkers", "4",
        "-compileReport",
        "-extra", extraDir,
        "-style", "OBF",
        "-optimize", "9" // 0=none, 9=max
    ]
  } else {
    println "Run production mode"
    args = [
        "com.test.portal.AppClientModule",
        "-war", buildDir,
        "-logLevel", "INFO",
        "-localWorkers", "4",
        "-compileReport",
        "-extra", extraDir,
        "-style", "OBF",
        "-optimize", "9" // 0=none, 9=max
    ]
  }

  maxHeapSize = "4G"
}

Server

gradle.build

plugins {
  id "org.springframework.boot" version "1.5.10.RELEASE"
}

dependencies {
...
}

jar.dependsOn compileGwt

jar {
  into("static") {
    from compileGwt.buildDir
  }
}

Questions:

  1. How properly call jar.dependsOn compileGwt from one module, a task from another module
  2. Script java.gradle Can I optimize it? Is there any duplication of code?
LeshaRB
  • 1,345
  • 2
  • 23
  • 44
  • https://docs.gradle.org/4.5.1/userguide/multi_project_builds.html#sec:project_and_task_paths – JB Nizet Feb 25 '18 at 07:42
  • I try add jar.dependsOn project(':gwt).compileGwt jar { into("static") { from project(':gwt).compileGwt.buildDir } } but it don't work – LeshaRB Feb 25 '18 at 08:58
  • Quoting: *The path of a task is simply its project path plus the task name, like “:bluewhale:hello”*. Quoting the example about cross-project dependencies: `dependsOn: ':producer:produce'`. Define "doesn't work", precisely. What are you doing, what do you expect to happen, what happens instead, precisely? – JB Nizet Feb 25 '18 at 09:05
  • I want to compileGwt when compiling jar. When this all was in one module everything worked perfectly. Now I'm trying to smash them Example one module https://github.com/feedm3/spring-boot-gwt/blob/master/build.gradle – LeshaRB Feb 25 '18 at 10:01
  • That doesn't answer any of my 3 questions. – JB Nizet Feb 25 '18 at 10:11
  • And what do you want to hear? I replied that I wanted to receive – LeshaRB Feb 25 '18 at 10:52
  • I use the following build scripts: ______. I execute the following command: _____. I expect the output to be: ______. And I expect the following files to be created: _____. But instead the output is ______. And the created files are _______. Saying "I had something working, I changed it, and it doesn't work anymore" doesn't help me understand what is wrong. – JB Nizet Feb 25 '18 at 11:01
  • 1) I download https://github.com/feedm3/spring-boot-gwt 2) I want separate springo-boot one module and gwt the second 3) How call properly call jar.dependsOn compileGwt from spring-boot module – LeshaRB Feb 25 '18 at 11:12

0 Answers0