Nice programing

단일 POM에서 두 개의 다른 maven exec-maven-plugin을 실행할 수 있습니까?

nicepro 2020. 12. 29. 08:28
반응형

단일 POM에서 두 개의 다른 maven exec-maven-plugin을 실행할 수 있습니까?


을 사용하여 다음 코드를 실행합니다 mvn exec:java com.mycompany.FooServer.

같은 실행할 수있는 다른 서버를 추가하고 싶습니다 mvn exec:java com.mycompany.BarServer.

단일 pom 파일 내에서 어떻게 수행합니까?

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.mycompany.FooServer</mainClass>
            </configuration>
        </plugin>
 </build>  

이 시도. 실행 중에 둘 이상의 실행이있을 수 있습니다. 실행중인 구성 요소를 이동하기 만하면됩니다. 플러그인에는 구성이 있지만 각 실행에는 별도의 구성 요소가있을 수도 있습니다.

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>first-execution</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.mycompany.FooServer</mainClass>
                    </configuration>
                </execution>
                <execution>
                    <id>second-execution</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.mycompany.BarServer</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
     </plugins>
 </build>

Maven 3.3.1 이상에서는 다음을 사용하여 ID로 실행을 실행할 수 있습니다.

mvn exec:java@id

이 경우 명령은 mvn exec:java@first-executionmvn exec:java@second-execution입니다. 자세한 내용은 이 답변 을 참조하십시오.


@tieTYT : 두 개의 다른 프로필을 사용하여 id로 실행을 선택할 수 있습니다.

mvn 테스트 -Pmanager

mvn 테스트 -Pproxy

<profiles> 
<profile>
    <id>proxy</id>
    <build>
    <plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <phase>test</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>pt.inesc.proxy.Proxy</mainClass>
                </configuration>
            </execution>
        </executions>
    </plugin>
    </plugins>
    </build>
</profile> 
<profile>
    <id>manager</id>
    <build>
    <plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            <execution>
                <phase>test</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>pt.inesc.manager.Manager</mainClass>
                </configuration>
            </execution>
        </executions>
    </plugin>
    </plugins>
    </build>
</profile> 
</profiles>

maven> 3.3.1에서는 실행 ID를 다음과 같이 지정할 수 있습니다.

mvn exec:java@execId

나를 위해 실행 블록에 구성을 포함하면 작동하지 않았고 메이븐은 메인 클래스가 설정되지 않았다고 불평했습니다. 그러나 Dario의 답변에 영감을 받아이 질문에 다음과 같이 대답하겠습니다.

<profiles>
    <profile>
        <id>foo</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <mainClass>com.mycompany.FooServer</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>bar</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <mainClass>com.mycompany.BarServer</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

그러면 다음을 사용하여 하나 또는 다른 서버를 실행할 수 있습니다.

mvn exec:java -Pfoo

또는

mvn exec:java -Pbar

건배,


해결책을 찾았습니다. I put <configuration> in <execution>

mvn clean test -Pfoo, bar를 사용할 수 있습니다.

<profiles>
    <profile>
        <id>foo</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <executions>
                        <execution>
                            <id>CountContinusIntegr-execution</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <mainClass>com.mycompany.FooServer</mainClass>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>bar</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <executions>
                        <execution>
                            <id>CountContinusIntegr-execution</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <mainClass>com.mycompany.BarServer</mainClass>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

나는 당신이 원하는 것이 불가능한 것이 두렵습니다 . mvn exec:java.pom 파일에서 다른 구성으로 동일한 exec-maven-plugin 목표를 직접 호출하는 방법을 찾을 수 없습니다 ( ).

말했다 즉, 당신은 그러나 간부-받는다는 - 플러그인의 여러 실행을 할 수 있습니다 . 문제는 목표를 직접 호출 할 수 없다는 것입니다. 여러 실행을 사용하고 특정 빌드 단계에 바인딩해야합니다.

You could also make use of the following solution that fitted me. You can still call one goal directly with it's configuration in the .pom:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
        <execution>
            <id>Acceptance Tests</id>
            <phase>integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>pybot</executable>
                <arguments>
                    <!--...-->
                </arguments>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <mainClass>pt.jandias.someapp.persistence.SchemaGenerator</mainClass>
        <arguments>
            <!--...-->
        </arguments>
    </configuration>
</plugin>

One could than use mvn exec:java and mvn integration-test at will.

ReferenceURL : https://stackoverflow.com/questions/8252107/is-it-possible-to-execute-two-different-maven-exec-maven-plugin-in-a-single-pom

반응형