Search code examples
javamavenintellij-idea

Why does my IntelliJ say that there's an error in my pom.xml?


Recently I added a pom.xml file to my java project in IntelliJ IDEA and I then made it into a Maven project. Though when I opened the pom.xml back again with IntelliJ, I saw 2 errors at "project" from the first project tag (<project). This error weirdly only appeared after I changed a letter that wasn't important and then never went away unless I went on a different window. Can somebody tell me why this is happening and how I can fix it?

Here is my pom.xml by the way:

<?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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.eplusplus</groupId>
    <artifactId>e++</artifactId>
    <version>1.0.0</version>

    <name>E++</name>
    <description>A brief description of my project</description>
    <url>http://www.example.com/my-project</url>

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

I expected there to be no error since even AI cannot identify a problem with this code.


Solution

    • Create an empty project directory like demo

    • Paste your pom.xml

    • Run command

      mvn dependency:copy-dependencies -DoutputDirectory=target/libs
      
    • Get result:

      [INFO] Scanning for projects...
      [ERROR] [ERROR] Some problems were encountered while processing the POMs:
      [ERROR] 'artifactId' with value 'e++' does not match a valid id pattern. @ line 9, column 17
       @ 
      [ERROR] The build could not read 1 project -> [Help 1]
      [ERROR]   
      [ERROR]   The project com.eplusplus:e++:1.0.0 (/home/demo/Desktop/demo/pom.xml) has 1 error
      [ERROR]     'artifactId' with value 'e++' does not match a valid id pattern. @ line 9, column 17
      [ERROR] 
      [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
      [ERROR] Re-run Maven using the -X switch to enable full debug logging.
      [ERROR] 
      [ERROR] For more information about the errors and possible solutions, please read the following articles:
      [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
      
    • [ERROR] 'artifactId' with value 'e++' does not match a valid id pattern. @ line 9, column 17 @

    • Find @ line 9, column 17 in your pom.xml

      <artifactId>e++</artifactId>
      

    In other words, Maven pom.xml artifactId does not allow the use of +.

    To solve this, rename your artifactId to match a valid id pattern.