我有以下 Maven 检查样式插件配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>https://someUtl.com/file.xml</configLocation>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
关注
<configLocation>https://someUtl.com/file.xml</configLocation>
file.xml可以通过浏览器下载,但需要登录名和密码。有没有办法在 Maven 或插件配置中指定这些登录名/密码?
最佳答案
在下面,这使用 Plexus这反过来又几乎完成了URL.openStream()
。
This answer展示了如何在 Java 代码中使用 Authenticator 来实现此目的,但我无法找到与之等效的 Maven。我倾向于说这是不可能的。
或者,您可以在单独的 mojo 执行中下载该文件,然后将 configLocation
指向下载的文件,该文件可以位于 target
文件夹下的任何位置.
我认为this answer给出了一些关于如何在 Maven 中下载文件的好主意。他们的第一点是,如果您的文件是 Maven Artifact ,您可以使用 Maven Dependency Plugin .
然后我们回到原点,因为如果您的 Checkstyle 配置要包含在 Maven Artifact 中,您不必将 configLocation
设置为远程位置,但您需要添加该 Artifact 作为 Checkstyle 插件执行的依赖
。由于 Maven 根据依赖关系定义了所有内容,这就是我要走的路,这正是我设置自己的 Checkstyle 配置的方式。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.totaalsoftware.incidentmanager</groupId>
<artifactId>checkstyle-config</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.config.xml</configLocation>
...
</configuration>
</plugin>
显然,在上面的示例中,checkstyle.config.xml
位于 checkstyle-config
JAR 的根目录中。
关于java - Maven checkstyle https 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19419231/