将Java项目转换为Maven时Pom文件出错

时间:2018-11-12 12:20:07

标签: java maven

我正在将Java项目转换为Maven。

我添加了这些依赖项

<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>Tippreports</groupId>
    <artifactId>Tippreports</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.8.0</version>
                        <type>maven-plugin</type>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-server</artifactId>
                        <version>3.141.5</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                        <version>6.14.3</version>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M1</version>
                        <type>maven-plugin</type>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

添加依赖项后,我无法以Maven安装或构建的方式运行

错误是

Error resolving version for plugin 'org.apache.maven.plugins:null' 
from the repositories [local (C:\Users\rck\.m2\repository),
central (http://repo.maven.apache.org/maven2)]:
Plugin not found in any plugin repository

我应该在上述指定位置创建一个文件夹,还是需要更改位置?

1 个答案:

答案 0 :(得分:5)

您的pom.xml对XSD无效。您首先应该使用一个IDE,它将向您显示问题。

正确的结构为<build><plugins><plugin>,如以下示例所示:

<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>Tippreports</groupId>
    <artifactId>Tippreports</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.5</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M1</version>
            </plugin>
        </plugins>
    </build>
</project>

您还将混合使用插件配置和相关性。依赖关系将移到pom.xml中的其他位置。