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.
<properties>
<jqassistant.version>1.9.1</jqassistant.version>
</properties>
Now add the plugin to the plugin management section of the pom.xml
.
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>${jqassistant.version}</version>
<executions>
<execution>
<id>default-cli</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
Note
|
The execution id default-cli ensures that the given plugin configuration is used if goals of the jQAssistant Maven Plugin are invoked directly from the command line, e.g. mvn jqassistant:scan .
|
To activate the plugin during the build you must add it to the plugin section.
<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.
$ mvn clean install
...
[INFO] --- jqassistant-maven-plugin:1.9.1:scan (default-cli) @ parent ---
[INFO] Scanning for jQAssistant plugins...
[INFO] [Asciidoc Report, CDI, Common, Core Analysis, Core Report, EJB3, GraphML, GraphQL, JAX-RS, JPA 2, JSON, JUnit, Java, Java EE 6, Maven 2 Repository, Maven 3, OSGi, RDBMS, Spring, TestNG, Tycho, XML, YAML].
[INFO] Connecting to store at 'file:/C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/jqassistant/store/'
[INFO] Initializing embedded Neo4j server 3.x
[INFO] Resetting store.
[INFO] Reset finished (removed 0 nodes, 0 relations).
[INFO] Entering C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/classes
[INFO] Leaving C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/classes (4 entries, 261 ms)
[INFO] Entering C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/test-classes
[INFO] Leaving C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/test-classes (4 entries, 79 ms)
[INFO] Entering C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/surefire-reports
[INFO] Leaving C:/Work/Development/Projects/jqassistant-101/src/main/tutorials/integrating-jqa-maven-plugin/target/surefire-reports (2 entries, 77 ms)
[INFO]
[INFO] --- jqassistant-maven-plugin:1.9.1:analyze (default-cli) @ parent ---
[INFO] Executing analysis for 'parent'.
[INFO] Will warn on violations starting from severity 'INFO'
[INFO] Will fail on violations starting from severity 'MAJOR'.
...
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.
$ 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.
MATCH (n:Class) RETURN n LIMIT 25