Question

How to cutomize the maven run configurations in eclipse or editing the parent pom.xml which should perform creation of child module packages with only specific contents included to jar.

My Project Strucutre: Parent MavenProject(pom type) with six child modules(jar type)

currently i have added maven profile concept to child module as shown below: I dont want to add the same thing across the child modules rather i want to add something in the parent pom.xml which pacakages all the child modules with specifc contents

<profiles>
        <profile>
            <id>client</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>2.4</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <classifier>client</classifier>
                                    <includes>
                                        <include>com/xxx/yyy/zzz/*</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

Directory layout:

My Project Structure
    -- ParentProject
    |-- pom.xml
    |-- childmodule 1
    |   |-- src/main/java
    |   |    |-com.pages.abc ->package1
    |   |    |-com.pages.def ->package2
    |   |    |-com.tests.abc ->package3 
    |   |    |-com.tests-def ->package4      
    |   |-- src/main/resources
    |   |    |-resourde folder 
    |   |-- target folder
    |   |-- pom.xml
    |   |   
    |
    |--child modules 2 to 6  (similar structure as childmodule 1)   

My actual reuirement is i need to skip all the test packages from the child module 1 to 5, except child module 6. I need to create the module jars excluding test packages for 1to5 modules. So added the profile "client" in parent pom.xml, am able to get the custom jars but am also getting default jar with all the packages. jars are present in target folder.

Était-ce utile?

La solution 2

you have both default jar and jar with classifier because you added execution with specific configuration to package phase, but maven-jar-plugin already have default execution on package phase.

If you want only one jar after mvn package command you should adjust default configuration of maven-jar-plugin

<profiles>
   <profile>
        <id>client</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <classifier>client</classifier>
                        <includes>
                            <include>com/xxx/yyy/zzz/*</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

or, as alternative, you can add id tag to execution with default-jar value, to allow only one execution of maven-jar-plugin

 <profiles>
    <profile>
        <id>client</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <id>default-jar</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <classifier>client</classifier>
                                <includes>
                                    <include>com/xxx/yyy/zzz/*</include>
                                </includes>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Autres conseils

Try adding the code below to a parent pom and extend that parent from all the modules which should be applying it. The proposed trick will check if a pattern of sources exist, (or, alternatively, do not exist).

<profiles>
    <profile>
        <id>client</id>

        <file>
            <exists>${basedir}/src/main/java/com/xxx/yyy/zzz/*</exists>
            <!-- Or, alternatively, -->
            <missing>${basedir}/src/main/resources/foo.properties</missing>
            -->
        </file>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <classifier>client</classifier>
                                <includes>
                                    <include>**/com/xxx/yyy/zzz/**</include>
                                </includes>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top