我正在尝试使用 maven-version-plugin 自动更新我的所有依赖项。尽管如此,我不想要 alpha 或 beta 版本。 因此,我创建了一个“规则文件”来排除这些版本。这是:
<ruleset comparisonMethod="maven"
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
<rule groupId="commons-logging" artifactId="commons-logging">
<ignoreVersions>
<ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion>
</ignoreVersions>
</rule>
</ruleset>
(此正则表达式来自 this thread 。)
问题是 Intellij IDEA 将 xmlns URI 和第二个 xsi:schemaLocation URI 设为红色,表示第一个 URI 为“URI 未注册”,并且“无法解析符号 ' http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd” '”为第二个。 The documentation 使用相同的值,所以我假设它们是 cargo 。
如何注册此 URI,然后修补无法解析的符号?
谢谢!
最佳答案
我发现实际架构并不位于 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd但在这里:http://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd
文档 ( http://www.mojohaus.org/versions-maven-plugin/version-rules.html ) 实际上给出了一个错误的示例文件,但确实说明了以下内容
The rule-set files must match the XSD schema.
这意味着xsi:schemaLocation
应更改为
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd"
完整来说,就变成了这样:
<ruleset
comparisonMethod="maven"
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
<rule groupId="commons-logging" artifactId="commons-logging">
<ignoreVersions>
<ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion>
</ignoreVersions>
</rule>
</ruleset>
更改 xsi:schemaLocation
后您可以使用<Alt>+<Enter>
并选择“获取外部资源”来解析架构并导入正确的命名空间。
或者:
您还可以告诉 IntelliJ IDEA 您认为架构位于何处。例如,您可以将文件下载到磁盘;按<Alt>+<Enter>
,选择“手动设置外部资源”并指向您刚刚下载的文件。 IntelliJ IDEA 现在应该忽略 xsi:schemaLocation
提示并使用您刚刚配置的覆盖。
使用 xsi:schemaLocation
的缺点指向远程文件的一个问题是,xml 处理器每次都必须即时下载它(这会影响性能,特别是当模式本身也指向外部模式时)。其次,由于它不是 https,因此您必须相信该文件在传输过程中没有被修改。通过预先下载该文件,您可以检查该文件,将其放置在受信任的位置并使用该已知版本。
关于xml - Maven 版本插件、规则集、规则和ignoreVersions 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44135921/