4

I'm trying to learn how to use Neo4j cypher with QueryDSL. So I downloaded the sources from the neo4j/cypher-dsl GitHub repository, and imported the project into eclipse as a Maven Project. However, when i try to compile and run the tests, i get a bunch of errors that a Q{Something} class cannot be resolved, for example:

QPerson cannot be resolved to a type

Here is a screenshot:

enter image description here

Did i forget to configure something? I couldn't find any tutorial about it or anything that states that i need to do anything special...

What is wrong?

Thanks!

gipouf
  • 1,221
  • 3
  • 15
  • 43

1 Answers1

6

Those "Q" files need to be generated by QueryDSL. The "maven-apt-plugin" takes care of this. The pom below shows what you need:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.github.timmystorms</groupId>
    <artifactId>neo4j-querydsl</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>maven-apt-plugin</artifactId>
                <version>1.0.4</version>
                <configuration>
                    <processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
                </configuration>
                <executions>
                    <execution>
                        <id>sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>src/main/java</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.mysema.maven</groupId>
                                        <artifactId>maven-apt-plugin</artifactId>
                                        <versionRange>[1.0.2,)</versionRange>
                                        <goals>
                                            <goal>process</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>1.9.RC1</version>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher-dsl</artifactId>
            <version>1.9.M04</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-lucene</artifactId>
            <version>2.8.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Optional test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

Check out my Gist that tests this setup. Just build with your code with e.g. mvn clean install.

EDIT: make sure to point to a JDK instead of a JRE when building since maven-apt-plugin needs the tools.jar.

tstorms
  • 4,941
  • 1
  • 25
  • 47
  • Hi, Thanks for your answer. I tried to follow your example in the link above, and created a new maven project with the pom.xml file you mentioned in the link, and the two classes (**Person** and **PersonTest**). So first, i got the following error in the pom.xml file:`Missing artifact org.neo4j:neo4j-cypher-dsl:jar:1.9.M04` so i changed teh dependency to neo4j-cypher-dsl version 1.7, because that's the latest release that i found [here](http://mvnrepository.com/artifact/org.neo4j/neo4j-cypher-dsl). after fixing the pom file, i still got errors, [as you can see here](http://tinyurl.com/cxc6tw4) – gipouf May 07 '13 at 10:42
  • maybe my eclipse is not configured properly? – gipouf May 07 '13 at 10:45
  • I've added the Neo4j repository to the pom on my Gist. Use neo4j-cypher-dsl 1.9.M04 again as 1.7 is too old. – tstorms May 07 '13 at 10:49
  • Also, it seems that you need to refresh your project (F5) in order for the generated class(es) to appear. This should be done after you've run `mvn clean install`. – tstorms May 07 '13 at 10:56
  • Hi, ok, so i used the updated pom file in the link (with the repositories sections the and 1.9.M04 version), then i ran `maven clean` from eclipse, and then `maven install` from eclipse, but during `maven install`, i got the following error: `Failed to execute goal com.mysema.maven:maven-apt-plugin:1.0.2:process (sources) on project neo4j-querydsl: null: MojoExecutionException` – gipouf May 07 '13 at 11:02
  • What's your project stucture like? Person (and the generated QPerson) should reside under src/main/java and your tests in src/test/java. Can you run the following statement `mvn clean install -e` and show me the stacktrace? – tstorms May 07 '13 at 11:05
  • 1
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29535/discussion-between-tstorms-and-royv) – tstorms May 07 '13 at 11:06