반응형

pluginManagement

  • 부모 프로젝트의 플러그인 설정 정보를 자식 프로젝트에 공유할 때 사용하는 플러그인 설정
  • parent, child 구성의 프로젝트가 아닐 경우 사용할 필요 없음
<!-- 부모 pom.xml 예시 -->
<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>            
                <configLocation>${basedir}/google_checks.xml</configLocation>
            </configuration>
            <dependencies>            
                <dependency>
                    <groupId>com.puppycrawl.tools</groupId>
                    <artifactId>checkstyle</artifactId>
                    <version>8.11</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</pluginManagement>
<!-- 자식 pom.xml 예시 (이렇게만 정의해서 사용해도 부모 pom.xml의 설정을 따라감) -->
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
    </plugin>
</plugins>

plugins

  • 해당 프로젝트에서만 사용하는 플러그인 설정
  • pom.xml 예시
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>            
            <configLocation>${basedir}/google_checks.xml</configLocation>
        </configuration>
        <dependencies>            
            <dependency>
                <groupId>com.puppycrawl.tools</groupId>
                <artifactId>checkstyle</artifactId>
                <version>8.11</version>
            </dependency>
        </dependencies>
    </plugin>
</plugins>

compiler 버전 지정

<properties>
    <java.version>11</java.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

특정 경로에 WAR 파일 떨구기

  • pom.xml
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <webappDirectory>${deploy.path}</webappDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
  • 실행
    mvn clean compile package -Ddeploy.path="../deploy"
    

main class 지정하기

  • pom.xml
    <build>
        <finalName>example</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.example.ExampleApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
  • 실행
    java -cp example.jar com.example.ExampleApplication
    
    java -jar example.jar
    

dependency 포함하여 패키징하기

pom.xml
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.test.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
패키징
mvn clean package
실행
java -jar {jar-name}-jar-with-dependencies.jar

원격 서버로 파일 전송

  • pom.xml
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>scp-to-remote</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <scp localFile="README.txt"
                                        remoteToFile="ubuntu@remote-server.example.com:/home/ubuntu"
                                        trust="true"
                                        verbose="true"
                                        keyfile="./.ssh/id_rsa"
                                        passphrase=""
                                />
                                <sshexec host="remote-server.example.com"
                                            trust="true"
                                            username="ubuntu"
                                            keyfile="./.ssh/id_rsa"
                                            command="cat README.txt"
                                />
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.jcraft</groupId>
                        <artifactId>jsch</artifactId>
                        <version>0.1.53</version>
                    </dependency>
                    <dependency>
                        <groupId>ant</groupId>
                        <artifactId>ant-jsch</artifactId>
                        <version>1.6.5</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    
  • 실행
    mvn package
    
반응형

+ Recent posts