Querydsl in subprojects


(Willie) #1

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?


(Dimitar Dimitrov) #2

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.


(Willie) #3

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.


(Dimitar Dimitrov) #4

Have you got an example project?


(James Justinic) #5

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.

For the curious, doodad = Annotation Processor

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.


(Willie) #6

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.


(James Justinic) #7

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.

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.

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.


(Willie) #8

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.


(James Justinic) #9

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.


(Willie) #10

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