如何在jQAssistant扫描WAR时排除外部依赖库或清理非自研数据?
Awesome that you're digging jQAssistant—it's such a powerful tool for code analysis! Let's break down how to solve your two key concerns: excluding external JARs during scanning, and cleaning up non-internal data from Neo4j.
You’re not missing anything—jQAssistant does support excluding specific JARs from your WAR’s lib directory, and it’s all handled via configuration. Here are the most reliable approaches:
Option 1: File Name Pattern Exclusion
If your internal JARs follow a consistent naming convention (e.g., end with -internal or start with your company prefix), you can use wildcard patterns to exclude everything else. Add this to your jqassistant.xml configuration file:
<scan> <path name="path/to/your-app.war"> <!-- Exclude all JARs in lib that don't end with "-internal" --> <exclude>**/lib/*[^-internal].jar</exclude> </path> </scan>
Option 2: Maven Coordinate Exclusion (More Precise)
If your project uses Maven, you can filter based on group IDs and artifact IDs to only include your company’s internal dependencies. This avoids relying on file names:
<scan> <path name="path/to/your-app.war"> <!-- First exclude all dependencies --> <exclude groupId="*" artifactId="*" /> <!-- Then re-include only your company's internal JARs --> <include groupId="com.yourcompany" artifactId="*" /> </path> </scan>
For Maven Plugin Users
If you’re running jQAssistant via the Maven plugin, add the exclusion rules directly to your pom.xml:
<build> <plugins> <plugin> <groupId>com.buschmais.jqassistant</groupId> <artifactId>jqassistant-maven-plugin</artifactId> <version>your-jqassistant-version</version> <configuration> <scan> <paths> <path>target/your-app.war</path> </paths> <excludes> <exclude>**/lib/*[^-internal].jar</exclude> </excludes> </scan> </configuration> </plugin> </plugins> </build>
If you’ve already scanned external dependencies and need to purge that data, you have two solid options:
Option 1: Targeted Cypher Query
Connect to your Neo4j instance and run a Cypher query to delete nodes and relationships associated with non-internal code. Adjust the filter to match your company’s package structure (e.g., com.yourcompany):
// First verify how many nodes will be deleted (safe check!) MATCH (c:Java:Class) WHERE NOT c.filename CONTAINS 'com/yourcompany' RETURN count(c) AS nonInternalClassCount; // If the count looks right, delete the nodes and their relationships MATCH (c:Java:Class) WHERE NOT c.filename CONTAINS 'com/yourcompany' DETACH DELETE c;
You can extend this to other node types (like Java:Method, Java:Field) if needed, but starting with Class covers most of the external dependency data.
Option 2: Full Database Reset
If you want a clean slate, use jQAssistant’s built-in clean command to wipe the entire Neo4j database before re-scanning with your exclusion rules:
jqassistant clean
Then run your scan command again—this time only your internal code will be imported into Neo4j.
内容的提问来源于stack exchange,提问作者eerriicc

