2017-05-24 2 views
0

Spring Boot 기반 프로젝트에서 동일한 프로젝트에서 두 가지 빌드를 만들고 싶습니다.스프링 부트 메이븐 플러그인이있는 프로파일에만 소스 패키지 및 종속성을 포함하십시오.

생성되는 빌드에 대한 결정은 maven 프로필이어야합니다.

특정 폴더 src/main/java/com/example/demo/full과 특정 종속성을 포함하는 하나의 빌드 (전체) 및 해당 종속성을 포함하지 않는 두 번째 빌드 (default 또는 light) 빌드를 만들고 싶습니다.

빌드 full 작품에 대한 종속성을 포함

,하지만 난 폴더 src/main/java/com/example/demo/full에만 full 빌드 컴파일되어 있는지 확인하는 방법을 모르겠어요. 여기

pom.xml :

<?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> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.3.RELEASE</version> 
    </parent> 

    <groupId>com.example</groupId> 
    <artifactId>demo</artifactId> 
    <version>1.0</version> 
    <packaging>jar</packaging> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
    </dependencies> 

    <build> 
     <finalName>demo</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <useSystemClassLoader>false</useSystemClassLoader> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <profiles> 
     <profile> 
      <id>full</id> 
      <dependencies> 
       <dependency> 
        <groupId>org.apache.poi</groupId> 
        <artifactId>poi-ooxml</artifactId> 
        <version>3.16</version> 
       </dependency> 
      </dependencies> 
     </profile> 
    </profiles> 

</project> 

어떻게 난 단지 프로필 full 컴파일 언급 된 소스 폴더를 관리 할 수 ​​있습니까?

+0

maven 프로필에서만 컴파일해야하는 Java 패키지를 별도의 소스에 넣습니다. 'scr/full-profile/java .....'폴더에 저장하고 특정 프로파일에만 포함시킵니다. – matthias

+0

좋은 @matthias가 들리지만 특정 프로필에 대해서만이 "포함"을 달성하는 방법은 무엇입니까? – yglodt

답변

1

scr\foo과 같은 두 번째 src 폴더를 추가하고이 src 폴더를 구성하는 maven에 프로필을 추가하십시오.

<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"> 

<build> 
    ... 
</build> 

<profiles> 
    <profile> 
     <id>extraSource</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>build-helper-maven-plugin</artifactId> 
        <version>3.0.0</version> 
        <executions> 
         <execution> 
          <id>add-source</id> 
          <phase>generate-sources</phase> 
          <goals> 
           <goal>add-source</goal> 
          </goals> 
          <configuration> 
           <sources> 
            <source>src/foo/</source> 
           </sources> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

여기 소스 폴더 받는다는 Build Helper Plugin위한 플러그인을 사용하여 첨가한다. specific profile의 빌드 섹션에 임베드되어 있으므로이 프로필로 maven을 실행하는 동안에 만 활성화됩니다 (활성화 섹션 참조).