title: Java QueryDSL and Gradle Kotlin DSL
body: <p>We are migrating our Groovy gradle build files to KotlinDSL and I am stuck with configuring the generation of QueryDSL classes.</p>
  
  <p>The entity classes are written in java and the QDSL files should be in java too.</p>
  
  <p>The working groovy build file code snippet:</p>
  
  <pre><code>sourceSets {
      generated.java { srcDirs = ['src/main/generated']}
  }
  
  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.mysema.query.apt.jpa.JPAAnnotationProcessor"]
      destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
  }
  
  compileJava {
      dependsOn generateQueryDSL
      source generateQueryDSL.destinationDir
  }
  
  compileGeneratedJava {
      dependsOn generateQueryDSL
      options.warnings = false
      classpath += sourceSets.main.runtimeClasspath
  }
  </code></pre>
  
  <p>This is my rewrite of the code in KotlinDSL:</p>
  
  <pre><code>val querydsl by configurations.creating
  
  val generated by java.sourceSets.creating {
      java.srcDirs("build/generated/java")
  }
  
  tasks {
      val generateQueryDsl by creating(JavaCompile::class.java) {
          group = "build"
          description = "Generate QueryDSL classes"
          classpath = configurations.compile + querydsl
          options.compilerArgs = listOf("-proc:only", "-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor")
          destinationDir = generated.java.srcDirs.first()
      }
  
      getByName&lt;JavaCompile&gt;("compileJava") {
          dependsOn(generateQueryDsl)
          source(generateQueryDsl.destinationDir)
      }
  
      getByName&lt;JavaCompile&gt;("compileGeneratedJava") {
          dependsOn(generateQueryDsl)
          options.isWarnings = false
          classpath += java.sourceSets["main"].runtimeClasspath
      }
  }
  </code></pre>
  
  <p>When I run the <code>generateQueryDsl</code> task, I got NO-SOURCE and no QDSL files generated:</p>
  
  <pre><code>&gt; Task :common:compileKotlin UP-TO-DATE
  &gt; Task :common:generateGrammarSource UP-TO-DATE
  &gt; Task :common:compileJava UP-TO-DATE
  &gt; Task :common:processResources UP-TO-DATE
  &gt; Task :common:classes UP-TO-DATE
  &gt; Task :common:inspectClassesForKotlinIC UP-TO-DATE
  &gt; Task :common:jar UP-TO-DATE
  &gt; Task :common-db:compileKotlin UP-TO-DATE
  &gt; Task :common-db:compileJava UP-TO-DATE
  &gt; Task :common-db:processResources UP-TO-DATE
  &gt; Task :common-db:classes UP-TO-DATE
  &gt; Task :common-db:inspectClassesForKotlinIC UP-TO-DATE
  &gt; Task :common-db:jar UP-TO-DATE
  &gt; Task :core:generateQueryDsl NO-SOURCE
  </code></pre>
  
  <p>I am not sure, but have a feeling that I could do this generation much simpler, but I ran out of the ideas.</p>