简体   繁体   English

如何修复 maven pom.xml 中不可解析的 pom 错误?

[英]how to fix non-parseable pom error in maven pom.xml?

I am a beginner to Maven .我是Maven的初学者。 I am learning to write custom checks for Java code using Maven.我正在学习使用 Maven 为 Java 代码编写自定义检查 I am having a sample project that I downloaded from GitHub.我有一个从 GitHub 下载的示例项目。

This is the entire pom.xml file of the project and it shows error in line 1:这是项目的整个pom.xml文件,它在第 1 行显示错误:

<xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonarsource.samples</groupId>
<artifactId>java-custom-rules</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sonar-plugin</packaging>
<name>SonarQube Java Custom Rules Example</name>
<description>Java Custom Rules Example for SonarQube</description>
<inceptionYear>2016</inceptionYear>


<properties>
    <sslr.version>1.21</sslr.version>
    <gson.version>2.6.2</gson.version>
    <sonar.version>6.7.4</sonar.version>
    <sonarjava.version>5.5.0.14655</sonarjava.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.sonarsource.sonarqube</groupId>
        <artifactId>sonar-plugin-api</artifactId>
        <version>${sonar.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>sonar-java-plugin</artifactId>
        <type>sonar-plugin</type>
        <version>${sonarjava.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.sslr-squid-bridge</groupId>
        <artifactId>sslr-squid-bridge</artifactId>
        <version>2.6.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.sonar.sslr</groupId>
                <artifactId>sslr-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.sonar</groupId>
                <artifactId>sonar-plugin-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.sonar.sslr</groupId>
                <artifactId>sslr-xpath</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>java-checks-testkit</artifactId>
        <version>${sonarjava.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>${gson.version}</version>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.sslr</groupId>
        <artifactId>sslr-testing-harness</artifactId>
        <version>${sslr.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>19.0</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.6.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>0.9.30</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
            <artifactId>sonar-packaging-maven-plugin</artifactId>
            <version>1.17</version>
            <extensions>true</extensions>
            <configuration>
                <pluginKey>java-custom</pluginKey>
                <pluginName>Java Custom Rules</pluginName>
                <pluginClass>org.sonar.samples.java.MyJavaRulesPlugin</pluginClass>
                <sonarLintSupported>true</sonarLintSupported>
                <sonarQubeMinVersion>6.7</sonarQubeMinVersion>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <!-- only required to run UT - these are UT dependencies -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.apache.commons</groupId>
                                <artifactId>commons-collections4</artifactId>
                                <version>4.0</version>
                                <type>jar</type>
                            </artifactItem>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-api</artifactId>
                                <version>6.0</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-webmvc</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-webmvc</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-web</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-context</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/test- 
                                           jars</outputDirectory>
                      </configuration>
                  </execution>
              </executions>
           </plugin>
       </plugins>
    </build>

  </project>

The error is:错误是:

> Project build error: Non-parseable POM
> C:\Users\swathi.TRN\Downloads\sonar-custom-rules-examples-master\sonar-custom-rules-examples-master\java-custom-rules\pom.xml:
> start tag unexpected character ? (position: START_DOCUMENT seen <xml
> version="1.0" encoding="UTF-8"?... @1:36)

I would really be thankful, if someone can help me fix this.我真的很感激,如果有人能帮我解决这个问题。 I am ready to provide you with any more inputs, if required.如果需要,我随时准备为您提供更多信息。

And also, if possible provide me with some links where I can learn how to write custom checks in Maven.而且,如果可能,请为我提供一些链接,我可以在其中学习如何在 Maven 中编写自定义检查。

Add "?"添加 ”?” between "<" and "xml" “<”和“xml”之间

Edit : Try this pom.xml , I was able to build sucessfully with below .编辑:试试这个 pom.xml,我能够用下面的成功构建。

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonarsource.samples</groupId>
<artifactId>java-custom-rules</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sonar-plugin</packaging>
<name>SonarQube Java Custom Rules Example</name>
<description>Java Custom Rules Example for SonarQube</description>
<inceptionYear>2016</inceptionYear>


<properties>
    <sslr.version>1.21</sslr.version>
    <gson.version>2.6.2</gson.version>
    <sonar.version>6.7.4</sonar.version>
    <sonarjava.version>5.5.0.14655</sonarjava.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.sonarsource.sonarqube</groupId>
        <artifactId>sonar-plugin-api</artifactId>
        <version>${sonar.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>sonar-java-plugin</artifactId>
        <type>sonar-plugin</type>
        <version>${sonarjava.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.sslr-squid-bridge</groupId>
        <artifactId>sslr-squid-bridge</artifactId>
        <version>2.6.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.sonar.sslr</groupId>
                <artifactId>sslr-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.sonar</groupId>
                <artifactId>sonar-plugin-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.sonar.sslr</groupId>
                <artifactId>sslr-xpath</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>java-checks-testkit</artifactId>
        <version>${sonarjava.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>${gson.version}</version>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.sslr</groupId>
        <artifactId>sslr-testing-harness</artifactId>
        <version>${sslr.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>19.0</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.2</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.6.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>0.9.30</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
            <artifactId>sonar-packaging-maven-plugin</artifactId>
            <version>1.17</version>
            <extensions>true</extensions>
            <configuration>
                <pluginKey>java-custom</pluginKey>
                <pluginName>Java Custom Rules</pluginName>
                <pluginClass>org.sonar.samples.java.MyJavaRulesPlugin</pluginClass>
                <sonarLintSupported>true</sonarLintSupported>
                <sonarQubeMinVersion>6.7</sonarQubeMinVersion>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <!-- only required to run UT - these are UT dependencies -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.apache.commons</groupId>
                                <artifactId>commons-collections4</artifactId>
                                <version>4.0</version>
                                <type>jar</type>
                            </artifactItem>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-api</artifactId>
                                <version>6.0</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-webmvc</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-webmvc</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-web</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-context</artifactId>
                                <version>4.3.3.RELEASE</version>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/test- 
                                           jars</outputDirectory>
                      </configuration>
                  </execution>
              </executions>
           </plugin>
       </plugins>
    </build>

  </project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM