簡體   English   中英

自定義Maven Checkstyle插件

[英]Customise maven checkstyle plugin

我正在嘗試創建自定義樣式。 SNAPSHOT已經在聲吶類型上使用了,但是我嘗試對其進行測試的測試項目無法實現依賴。 錯誤是

[INFO] Building TestProject 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-checkstyle-plugin:2.10:checkstyle (default-cli) @ TestProject ---
Downloading: http://repository.apache.org/snapshots/com/novoda/novoda-checkstyle-checks/1.0-SNAPSHOT/maven-metadata.xml
Downloading: http://repository.apache.org/snapshots/com/novoda/novoda-checkstyle-checks/1.0-SNAPSHOT/novoda-checkstyle-checks-1.0-SNAPSHOT.pom
[WARNING] The POM for com.novoda:novoda-checkstyle-checks:jar:1.0-SNAPSHOT is missing, no dependency information available
Downloading: http://repository.apache.org/snapshots/com/novoda/novoda-checkstyle-checks/1.0-SNAPSHOT/novoda-checkstyle-checks-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.993s
[INFO] Finished at: Thu Aug 08 16:37:42 BST 2013
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.10:checkstyle (default-cli) on project TestProject: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:2.10:checkstyle failed: Plugin org.apache.maven.plugins:maven-checkstyle-plugin:2.10 or one of its dependencies could not be resolved: Could not find artifact com.novoda:novoda-checkstyle-checks:jar:1.0-SNAPSHOT in apache.snapshots (http://repository.apache.org/snapshots) -> [Help 1]

這是項目pom

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>TestProject</groupId>
  <artifactId>TestProject</artifactId>
  <version>0.0.1</version>

  <properties>
    <checkstyle.config.location>properties/checkstyle-configuration.xml</checkstyle.config.location>
  </properties>

  <repositories>
    <repository>
      <id>sonatype-nexus-snapshots</id>
      <name>Sonatype Nexus Snapshots</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.10</version>
        <dependencies>
          <dependency>
            <groupId>com.novoda</groupId>
            <artifactId>novoda-checkstyle-checks</artifactId>
            <version>1.0-SNAPSHOT</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

</project>

知道為什么不下載依賴插件嗎?

解決方法很簡單。 因為我要獲取的是插件,所以我需要使用pluginRepositories而不是repositories

  <pluginRepositories>
    <pluginRepository>
      <id>sonatype-nexus-snapshots</id>
      <name>Sonatype Nexus Snapshots</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>

您可以看到maven正在錯誤的倉庫中尋找快照http://repository.apache.org/snapshots/
您的工件在https://oss.sonatype.org/content/repositories/snapshots

您用來運行的pom不是定義sonatype <repository>的pom,或者它正在被覆蓋。 檢查運行maven的文件夾中的有效pom並找到定義,您可能會發現它是apache.org而不是sonatype的

另外,通常不建議在pom中使用<repository> ,因為它會使工件無法被無法訪問特殊<repository>的其他人使用,請查看本文 我更喜歡在settings.xml中配置自定義存儲庫(sonatype快照)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM