Maven antrun plugin: element target is not allowed here

Errors of the same type look like this:

Element target is not allowed here
Cannot resolve symbol copy
Cannot resolve symbol fileset
Cannot resolve symbol copydir

Most likely this means that you have included the plugin in the pom.xml like this:

<plugin>

  <groupId>org.apache.maven.plugins</groupId>

  <artifactId>maven-antrun-plugin</artifactId>

  <executions>

    <execution>

      <id>copy-artifacts</id>
      <phase>package</phase>

      <goals>

        <goal>run</goal>

      </goals>

      <configuration>

        <target name="target_copy">
          ...

        </target>
      </configuration>

    </execution>

  </executions>

</plugin>

The reason for the error is that the plugin version is not specified. Let’s specify, for example, 1.8:

<plugin>
    
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>

    <executions>

        ...
    </executions>

</plugin>

After that, you need to load changes from pom.xml to Maven and the error will disappear.

Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *