This tutorial shows you how you can use jQAssistant in a Maven project by integrating the jQAssistant Plugin.

Note
This tutorial is written for version 1.3.0 of jQAssistant. In further versions of jQAssistant some aspects might changed.

1. Add the Plugin to the Maven POM

Open the top-level pom.xml of your project in any editor and add a property called jqassistant.version to the properties of your Maven project. It is a good pratice to managed version information with the help of properties. So you can migrate to a newer version by just changing the property value.

Definition of the jQAssistant version to use
<properties>
  <jqassistant.version>1.3.0</jqassistant.version>
</properties>

Now add the plugin to the plugin management section of the pom.xml.

Declaration of the jQAssistant Maven plugin
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>com.buschmais.jqassistant</groupId>
      <artifactId>jqassistant-maven-plugin</artifactId>
      <version>${jqassistant.version}</version>
      <executions>
        <execution>
          <id>default</id>
          <goals>
            <goal>scan</goal>
            <goal>analyze</goal>
          </goals>
          <configuration>
            <warnOnSeverity>INFO</warnOnSeverity>
            <failOnSeverity>MAJOR</failOnSeverity>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</pluginManagement>

Now Maven knows that you would like to use the jQAssistant Plugin for Maven and which version of it. Furthermore basic configuration is provided

  • the goals that should be executed by default

  • the severities for log warnings or failing about if rules have failed during analysis

To activate the plugin during the build you must add it to the plugin section.

Configuration of the jQAssistant Maven plugin
<plugins>
  <plugin>
    <groupId>com.buschmais.jqassistant</groupId>
    <artifactId>jqassistant-maven-plugin</artifactId>
  </plugin>
</plugins>

2. Running the plugin during the build

Using the shown configuration jQAssistant will be executed during a normal Maven build.

Running a build including the jQAssistant Maven plugin
$ mvn clean install
...
[INFO]
[INFO] --- jqassistant-maven-plugin:1.3.0:scan (default) @ parent ---
[INFO] Loaded jQAssistant plugins [CDI, Common, Common Test, Core Analysis, EJB3, GraphML, JAX-RS, JPA 2, JSON, JUnit, Java, Java 8, Java EE 6, Maven 3, OSGi, RDBMS, TestNG, Tycho, XML, YAML].
[INFO] Connecting to store at 'file:/Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/jqassistant/store/'
[INFO] Resetting store.
[INFO] Reset finished (removed 138 nodes, 424 relations).
[INFO] Entering /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/classes
[INFO] Leaving /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/classes (4 entries, 209 ms)
[INFO] Entering /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/test-classes
[INFO] Leaving /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/test-classes (4 entries, 65 ms)
[INFO] Entering /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/surefire-reports
[INFO] Leaving /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/surefire-reports (2 entries, 50 ms)
[INFO]
[INFO] --- jqassistant-maven-plugin:1.3.0:analyze (scan-and-analyze) @ parent ---
[INFO] Executing analysis for 'parent'.
[INFO] Reading rules from directory /Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/jqassistant
[INFO]
...
Tip
If you want skip the execution of jQAssistant for any reason you can run Maven with -Djqassistant.skip.

jQAssistant will create during its run a new directory jqassistant/store below the created target directory. It contains the Neo4j database with the result of the jQAssistant’s scan.

3. Accessing the generated database

The Maven plugin also contains a goal called server. Running the plugin with this goal runs an embedded Neo4j server and makes the Neo4j web console available. On of the last lines of the output contains the server and port of the web console.

Running the embedded Neo4j server
$ mvn jqassistant:server
...
[INFO] --- jqassistant-maven-plugin:1.3.0:server (default-cli) @ parent ---
[INFO] Loaded jQAssistant plugins [CDI, Common, Common Test, Core Analysis, EJB3, GraphML, JAX-RS, JPA 2, JSON, JUnit, Java, Java 8, Java EE 6, Maven 3, OSGi, RDBMS, TestNG, Tycho, XML, YAML].
[INFO] Connecting to store at 'file:/Users/obf/jqa/jqa-101/integrating-jqa-maven-plugin/target/jqassistant/store/'
2017-08-20 15:46:26.526+0200 INFO  [o.n.s.CommunityNeoServer] No SSL certificate found, generating a self-signed certificate..
2017-08-20 15:46:26.770+0200 INFO  [o.n.s.CommunityNeoServer] Starting HTTP on port 7474 (8 threads available)
2017-08-20 15:46:26.956+0200 INFO  [o.n.s.w.Jetty9WebServer] Mounting static content at /webadmin
2017-08-20 15:46:26.997+0200 INFO  [o.n.s.w.Jetty9WebServer] Mounting static content at /browser
Aug 20, 2017 3:46:27 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFORMATION: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
Aug 20, 2017 3:46:27 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFORMATION: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
Aug 20, 2017 3:46:27 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFORMATION: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
2017-08-20 15:46:27.514+0200 INFO  [o.n.s.CommunityNeoServer] Remote interface ready and available at http://localhost:7474/
[INFO] Running server for module your.company.project:parent:0.1.1-SNAPSHOT
[INFO] Press <Enter> to finish.

Now open your browser at http://localhost:7474/ and enter the following query. It returns all Java classes existing in your project.

Cypher query to find all Java classes
MATCH (n:Class) RETURN n LIMIT 25