Posted by December 16, 2013on
As you probably know,
maven-antrun-plugin provides a custom AttachArtifact task that is able to attach artifacts generated by Ant to the current Maven project. The usage is really straightforward with inline Ant targets, but an attempt to use this task with external build.xml results in an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (...) on project ...: An Ant BuildException has occured: The following error occurred while executing this line: [ERROR] C:\...\build.xml:158: Maven project reference not found: maven.project
[ The solution described here does not really work. See update at the bottom. ]
The solution is simple – external Ant invocation should inherit references from the inline target:
<plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>...</id> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <ant antfile="build.xml" target="..." inheritRefs="true" /> </target> </configuration> </execution> </executions> </plugin>
Update: It appears that this change eliminates the error, but the artifact is not actually attached. I’ve opened a bug report to the Maven Antrun Plugin team about that.