executing a script from maven inside a multi module project
I have this multi-module project.
In the beginning of each build I would like to run som开发者_运维问答e bat file.
So i did the following:
<profile>
<id>deploy-db</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
<configuration>
<executable>../database/schemas/import_databases.bat</executable>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
when i run the mvn verify -Pdeploy-db
from the root I get this script executed over and over again in each of my modules.
I want it to be executed only once, in the root module.
What is there that I am missing ?
Thanks
I might be mistaken but when you add a plugin to the <pluginManagement>
section each and every sub-module inherits it and "runs" it.
I think that you should move you exec-maven-plugin and its <execution>
to the normal <plugins>
section.
So the issue you're having is that you're trying to do something in the parent POM. That's not how parent poms are designed in maven (i.e. not "the maven way"). You should only perform actions in "leaf node" poms, the parents are just for aggregation and putting shared behavior that should be reused in each child.
So the simple answer at how to call your script is to analyze the dependencies between your children to determine which needs to happen first (and impose dependency if necessary to enforce this), then add the plugin to that child. If it doesn't fit well in that child for some reason, you can make another child that just performs this action.
On a side note, never reference relative file paths in maven. You're using "../database/schemas/import_databases.bat". If import_databases.bat isn't inside the project directory then assuming it's in the parent directory is asking for a mess. You should instead use something like "${basedir}/src/main/scripts/import_databases.bat"
精彩评论