# Querydsl in subprojects

**URL:** <https://discuss.gradle.org/t/querydsl-in-subprojects/24484>\
**Category:** Help/Discuss\
**Created:** [October 20, 2017, 10:51pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484 "2017-10-20T22:51:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![scphantm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/scphantm/32/5691_2.png) [@scphantm](https://discuss.gradle.org/u/scphantm)\
**Post date:** [October 20, 2017, 10:51pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/1 "2017-10-20T22:51:43Z")

</div>

I am running this config

```
project(":myappEntity") {
  dependencies {
    compile project(":myappCommon")

    compile group: 'org.hibernate', name: 'hibernate-core', version: '4.2.21.Final'
    compile group: 'org.springframework', name: 'spring-beans', version: spring_version
    compile("com.mysema.querydsl:querydsl-jpa:3.7.4")
    compile("com.mysema.querydsl:querydsl-apt:3.7.4:jpa")
  }
}

```

Now, the querydsl stuff brought in by the `:jpa` does a great job of generating my class files. The way it works is it bypasses generating `*.java` and goes directly to `*.class`. This is awesome.

Now, when i include `project(":myappEntity")` in the dependencies of project B, project B can’t find the resulting Q classes.

Intellij can’t find them either.

What do i need to add to get this to show up?

---

<div class="post-metadata">

**Author:** ![ddimitrov](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ddimitrov/32/141_2.png) [@ddimitrov](https://discuss.gradle.org/u/ddimitrov)\
**Post date:** [October 23, 2017, 7:30am UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/2 "2017-10-23T07:30:32Z")

</div>

> [@scphantm](#):
>
> Now, the querydsl stuff brought in by the :jpa does a great job of generating my class files. The way it works is it bypasses generating \*.java and goes directly to \*.class. This is awesome.

Are you sure the classes are generated? What generates them? Where is the output path?

You need to add the output path to your jar task (if it differs from ./build/classes/java/main) and everything should follow from there.

---

<div class="post-metadata">

**Author:** ![scphantm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/scphantm/32/5691_2.png) [@scphantm](https://discuss.gradle.org/u/scphantm)\
**Post date:** [October 23, 2017, 10:47am UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/3 "2017-10-23T10:47:29Z")

</div>

That’s what’s weird, the output dir is build/classes/Java/main. The Q\*.class files are there, just nothing sees them.

I have no idea how the rest of it works. You just include that Jpa dependency and some external doodad begins generating them on the compilejava task.

---

<div class="post-metadata">

**Author:** ![ddimitrov](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ddimitrov/32/141_2.png) [@ddimitrov](https://discuss.gradle.org/u/ddimitrov)\
**Post date:** [October 23, 2017, 2:14pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/4 "2017-10-23T14:14:46Z")

</div>

Have you got an example project?

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [October 23, 2017, 2:25pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/5 "2017-10-23T14:25:44Z")

</div>

> [@scphantm](#):
>
> The way it works is it bypasses generating \*.java and goes directly to \*.class. This is awesome.

With what you’ve posted, both the \*.java and \*.class file are generated into the classes directory and included in the jar / on the classpath.

> [@scphantm](#):
>
> I have no idea how the rest of it works. You just include that Jpa dependency and some external doodad begins generating them on the compilejava task.

For the curious, doodad = Annotation Processor

> [@scphantm](#):
>
> The Q\*.class files are there, just nothing sees them.

Taking what you have, I added an example entity in the entity project and usage of it in a “project B”, both directly copied and pasted from the querydsl website and everything works as expected (minus the additional, but non-breaking inclusion of the \*.java file).

Considering the most basic example project with querydsl extrapolated from your post works, you might be overlooking something impactful that’s not actually querydsl related.

---

<div class="post-metadata">

**Author:** ![scphantm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/scphantm/32/5691_2.png) [@scphantm](https://discuss.gradle.org/u/scphantm)\
**Post date:** [October 24, 2017, 12:45pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/6 "2017-10-24T12:45:44Z")

</div>

second look, your right about the java files. i did find a way to dump them into a generated folder, but i don’t care, i don’t want them in source control anyways. the `compile project(":myappEntity")` in the dependencies of project B is supposed to include the output of `myappEntity` right? If thats the case, im not sure why nothing else can see those class files.

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [October 24, 2017, 3:57pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/7 "2017-10-24T15:57:39Z")

</div>

> [@scphantm](#):
>
> the compile project(“:myappEntity”) in the dependencies of project B is supposed to include the output of myappEntity right?

The JAR file built for `myAppEntity` should contain the `Q*.class` files for each `@Entity` you have in the project. Using your configuration from the first post, I can grab an example entity from anywhere, add it to the project, and see the `Q*.java` and `Q*.class` files generated and included in the JAR. I can also reference the `Q*` classes in project B.

> [@scphantm](#):
>
> If thats the case, im not sure why nothing else can see those class files.

I’m taking “nothing else” to mean absolutely nothing that could consume these files. I am considering project B to be something else. I’m ignoring IntelliJ for now. If you’re really saying that you can’t even compile project B with references to the `Q*` classes, something is fundamentally wrong that needs to be addressed before focusing on anything more complicated.

> [@scphantm](#):
>
> i did find a way to dump them into a generated folder, but i don’t care, i don’t want them in source control anyways.

Even if you want the generated files to stay out of source control, you will likely need to isolate them for the IntelliJ case since IntelliJ needs to separately be able to work with these files. I don’t think it’s worth looking at this until it’s the only problem remaining though.

---

<div class="post-metadata">

**Author:** ![scphantm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/scphantm/32/5691_2.png) [@scphantm](https://discuss.gradle.org/u/scphantm)\
**Post date:** [October 24, 2017, 5:51pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/8 "2017-10-24T17:51:58Z")

</div>

> [@jjustinic](#):
>
> I’m taking “nothing else” to mean absolutely nothing that could consume these files. I am considering project B to be something else. I’m ignoring IntelliJ for now. If you’re really saying that you can’t even compile project B with references to the Q\* classes, something is fundamentally wrong that needs to be addressed before focusing on anything more complicated.

correct. from a command line, i get compile errors on project b saying it can’t find Q\*.class files.

```
project(":myappRepository") {
  dependencies {
    compile project(":myappEntity")
  }
}

project(":myappEntity") {

  dependencies {
    compile project(":myappCommon")

    compile group: 'org.hibernate', name: 'hibernate-core', version: '4.2.21.Final'
    compile group: 'org.springframework', name: 'spring-beans', version: spring_version
    compile("com.mysema.querydsl:querydsl-jpa:3.7.4")
    compile("com.mysema.querydsl:querydsl-apt:3.7.4:jpa")
  }
}

```

fails to compile the myappRepository project saying it can’t find a Q file that was generated (and visually verified) in the myappentity project.

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [October 24, 2017, 6:33pm UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/9 "2017-10-24T18:33:37Z")

</div>

I don’t think you’ve provided enough information for a third party to identify your current issue. My sample project with your snippets doesn’t seem to have the same problem. See it works for you and if that helps point out what is fundamentally different in your project or points out a relevant point to add to continue the discussion.

> **[jjustinic/gradle-forums-2017-08-24-querydsl](https://github.com/jjustinic/gradle-forums-2017-08-24-querydsl)**
>
> gradle-forums-2017-08-24-querydsl - https://discuss.gradle.org/t/querydsl-in-subprojects/24484

---

<div class="post-metadata">

**Author:** ![scphantm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/scphantm/32/5691_2.png) [@scphantm](https://discuss.gradle.org/u/scphantm)\
**Post date:** [October 25, 2017, 11:35am UTC](https://discuss.gradle.org/t/querydsl-in-subprojects/24484/10 "2017-10-25T11:35:44Z")

</div>

i gave up and told the dev team to strip it and write the queries by hand. they should be done today.
