2

我有以下 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 或插件配置中指定这些登录名/密码?

4

1 回答 1

3

在下面,这使用了Plexus,而Plexus 也差不多URL.openStream()

这个答案显示了如何Authenticator在 Java 代码中使用它,但我无法找到一个 Maven 等价物。我倾向于说这是不可能的。

或者,您可以在单独的 mojo 执行中下载该文件,然后将 指向下载的文件,该文件可能位于您文件夹configLocation的任何位置。target

我认为这个答案提供了一些关于如何在 Maven 中下载文件的好主意。他们的第一个是,如果您的文件是 Maven 工件,您可以使用Maven 依赖插件

然后我们回到原点,因为如果您的 Checkstyle 配置包含在 Maven 工件中,您不必设置configLocation到远程位置,但您可以将该工件添加dependency为您的 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-configJAR 的根目录中。

于 2013-10-17T06:50:12.890 回答