简体   繁体   中英

Eclipse Run Configuration - Multiple Run configurations in single configuration?

i have a situation where my Project MAIN contains SubProject A and SubProject B and when ever i make changes in SubProject A and SubProject B.

i have to do maven clean and maven install for SubProject A and SubProject B and then MAIN Project Update.

Is there any way to achieve all this in single configuration ?

Something like :

Configuration MainProject does: clean ,build A, clean,build B, clean,build MainProject.

Thanks

Is there any way to achieve all this in single configuration ?

Of course you can. This is a skeleton for a maven multi module project:

parent POM:

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

    <groupId>my.group</groupId>
    <artifactId>myProject</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <name>myProject</name>
    <url>http://maven.apache.org</url>
    <modules>
        <module>moduleA</module>
        <module>moduleB</module>
    </modules>
    <build>
          ....
    </build>

    <dependencyManagement>
        <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.4</version>
            <scope>test</scope>
        </dependency>
           ....
        </dependencies>
    </dependencyManagement>

    <dependencies>
           ....
    </dependencies>
</project>

Be aware of <packaging>pom</packaging> .

This is the POM for moduleA:

<?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>
    <parent>
        <artifactId>myProject</artifactId>
        <groupId>my.group</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>moduleA<artifactId>
    <name>moduleA</name>
    <packaging>jar</packaging>       <!-- this is default  -->
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
          <!-- no version here, see dependencyManagemant in parent POM -->
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
          <!-- no version here, see dependencyManagemant in parent POM -->                <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Analog for moduleB, but with dependency to moduleA.

<?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>
    <parent>
        <artifactId>nbaWorker</artifactId>
        <groupId>de.lgn.aaabk</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>moduleB</artifactId>
    <name>moduleB</name>
    <packaging>jar</packaging>       <!-- this is default  -->

    <dependencies>
        <dependency>
            <groupId>my.group</groupId>
            <artifactId>moduleA</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
          <!-- no version here, see dependencyManagemant in parent POM -->
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
          <!-- no version here, see dependencyManagemant in parent POM -->                <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Now, you can call mvn clean install on the parent whenever you make changes on a module.

Here are more informations: Tutorial How do I ...

From Sonatype

From maven Homepage . At this time, not so helpful, and there is a broken link.

To do that I declare a profile in my top level parent POM like this

    <profile>
        <id>build-all</id>                              
        <modules>
            <module>MAIN</module>       
            <module>SubProjectA</module>        
            <module>SubProjectB</module>                                    
        </modules>
    </profile>      

At the eclipse Run Configuration use the parent POM path as base directory and "build-all" as profile.

Remember that you must declare the parent POM as parent of the other POMS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM