SW-PRODUCT/개발

간만에 Maven Plugin 끄적임

굴돌 2014. 9. 24. 12:04


결론

archetype으로 기본틀 만든 후에 원하는 기능 넣자.

참 쉽죠?


mvn archetype:generate \
  -DgroupId=sample.plugin \
  -DartifactId=hello-maven-plugin \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-plugin


관련링크: http://maven.apache.org/guides/plugin/guide-java-plugin-development.html



Integration-Test도 쉽게 된다.

archetype으로 만들면 IT 샘플도 있으니 쉽게 테스트 가능하다.


mvn -Prun-its integration-test




Java8에서...

그런데 Java8에서 Annotation을 쓰고 싶으면 아래 두 가지 작업을 해줘야 한다.

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <goalPrefix>mtwebtest</goalPrefix>
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>
                <executions>
                    <execution>
                        <id>mojo-descriptor</id>
                        <goals>
                            <goal>descriptor</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                    <execution>
                        <id>help-goal</id>
                        <goals>
                            <goal>helpmojo</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
            </plugin>
...


사실 위 두 작업은 Java annotation 기반 plugin 개발 페이지에 설명된 내용이기는 하나 없어도 잘 동작했는데 (혹은 했던것 같은데) Java8에서는 저게 없으면 annotaion 기반 @Mojo를 인식하지 못한다.


참고로, Mojo를 제대로 인식했는지 여부는 아래 명령을 이용하면 쉽게 알 수 있다.

mvn plugin:descriptor



goal prefix의 경우

maven-plugin-plugin 설정할 때 <goalPrefix>로 지정해주는 것이 제일 속편한 듯.

이게 충돌나면 골치아프겠지만서도..;;

몇 가지 자동으로 찾아주는 룰이 있는것 같기는 한데 헷갈린다...;;

* Plugin Prefix Resolution 설명서 : http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html


            <plugin>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <goalPrefix>mtwebtest</goalPrefix>
...



mojo-executo: 플러그인에서 Mojo 실행하기...

현재 관리하는 플러그인이 ant 실행을 위해 mojo-executor를 사용한다.

링크: https://github.com/TimMoore/mojo-executor


2014년을 기점으로 원저작자가 추가개발은 중단하고 머지만 해주는 상황.