jQassistant多项目扫描共用Neo4j库失败问题求助
使用1.10.1版本的jqassistant-maven-plugin,搭配共用Neo4j数据库汇总多个Spring Boot应用的扫描信息,用来识别跨应用API调用关系和循环依赖情况。已经禁用了数据库重置功能,首次Maven构建能正常完成,但执行第二个应用的扫描时抛出以下错误:
org.neo4j.driver.exceptions.DatabaseException: The shortest path algorithm does not work when the start and end nodes are the same. This can happen if you perform a shortestPath search after a cartesian product that might have the same start and end nodes for some of the rows passed to shortestPath. If you would rather not experience this exception, and can accept the possibility of missing results for those rows, disable this in the Neo4j configuration by setting
cypher.forbid_shortestpath_common_nodesto false. If you cannot accept missing results, and really want the shortestPath between two common nodes, then re-write the query using a standard Cypher variable length pattern expression followed by ordering by path length and limiting to one result.
各应用类的全限定名没有冲突,只有部分类名称相似,目前无法确定问题原因和解决方法。
补充:触发错误的自动生成查询语句如下:
UNWIND $batch as entry CREATE (n:File:Directory:Package:Java) SET n=entry['n'] RETURN collect({oldId:entry['id'], newId:id(n)}) as nodes', {batch=[{n={name=controller, fileName=/com/mycompany/client/controller, fqn=com.mycompany.client.controller}, id=-9}]}
该查询由插件自动生成,无法手动修改。
1. 修改Neo4j配置跳过异常
根据错误提示,直接修改Neo4j配置关闭该异常检查:
- 若使用jqassistant默认的嵌入式Neo4j,在Maven插件配置中添加JVM参数传递配置:
<plugin> <groupId>org.jqassistant</groupId> <artifactId>jqassistant-maven-plugin</artifactId> <version>1.10.1</version> <configuration> <jvmArgs> <jvmArg>-Dcypher.forbid_shortestpath_common_nodes=false</jvmArg> </jvmArgs> <resetDatabase>false</resetDatabase> <!-- 其他原有配置 --> </configuration> </plugin>
- 若使用独立部署的Neo4j服务,找到
neo4j.conf配置文件,添加cypher.forbid_shortestpath_common_nodes=false,重启服务即可。
2. 排查包节点重复问题
虽然类的全限定名无冲突,但第二个应用扫描时要创建的com.mycompany.client.controller包节点可能已在首次扫描中存在。jqassistant处理重复节点时,内部可能触发最短路径相关查询逻辑,进而抛出异常。可以尝试:
- 升级jqassistant到最新稳定版,新版本可能修复了重复节点处理时的查询问题;
- 首次扫描后,手动检查Neo4j数据库中是否存在相同
fqn的Package节点,若存在,调整第二个应用的扫描范围,排除这些重复的包路径。
3. 启用增量扫描模式
在插件配置里开启增量扫描,避免重复处理已存在的节点:
<plugin> <groupId>org.jqassistant</groupId> <artifactId>jqassistant-maven-plugin</artifactId> <version>1.10.1</version> <configuration> <resetDatabase>false</resetDatabase> <incremental>true</incremental> <!-- 其他原有配置 --> </configuration> </plugin>
内容的提问来源于stack exchange,提问作者Venkat

