2013-04-16 106 views
1

問題: 如何在Nexus上禁用重新部署時發佈具有2個獨佔配置文件的maven項目?如何在重新部署禁用時發佈多個配置文件項目

實施例(編輯): 我在pom.xml 2條曲線的行家項目MyArtifact(P1和P2)至極生成2周型動物的耳朵。每個配置文件將maven-ear-plugin配置爲包含不同的模塊並自動生成application.xml。生成的工件是MyArtifact-1.0-P1.ear(2個戰爭模塊)和MyArtifact-1.0-P2.ear(3個戰爭模塊)。

問題1(重新部署到關係)

  1. 當我執行 「」 一切順利(戰爭和POM被部署到的Nexus)
  2. 當我執行 「mvn deploy -P P2」 的錯誤! Nexus抱怨重新部署pom.xml。

問題2(Maven的釋放小插件)

當使用maven-release-plugin釋放了多個配置文件,行家做了很多的事情(檢驗和標籤CSM,更新POM版本,圈標記,提交給CSM等)。至少,對於每個配置文件執行都不得不重新發布/重新標記是沒有效率也不實際的。

回答

0

是啊!

使用配置文件,我使用maven <executions>功能:每個配置文件我有1執行。每次執行必須在不同的工作文件夾中生成資源。每個神器都有不同的分類器。部署maven時會發現3件神器(pom,ear,ear),並將它們部署到Nexus上。

下面是例子。請讓我知道你有任何問題:

<plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-ear-plugin</artifactId> 
     <executions> 
      <execution> 
       <!-- Disable default execution --> 
       <id>default-ear</id> 
       <phase>none</phase> 
      </execution> 
      <execution> 
       <!-- Disable default execution --> 
       <id>default-generate-application-xml</id> 
       <phase>none</phase> 
      </execution> 
      <execution> 
       <!-- execution for profile P1 --> 
       <id>P1</id> 
       <goals> 
        <goal>ear</goal> 
        <goal>generate-application-xml</goal> 
       </goals> 
       <configuration> 
        <!-- Different working directory for each profile (very important) --> 
        <workDirectory>target/P1</workDirectory> 
        <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir> 
        <generateApplicationXml>true</generateApplicationXml> 
        <displayName>MyArtifactLibraryP1</displayName> 
        <!-- Different classifier for each profile (very important) --> 
        <classifier>P1</classifier> 
        <modules> 
         <jarModule> 
          <groupId>com.example</groupId> 
          <artifactId>MyWar1</artifactId> 
          <includeInApplicationXml>true</includeInApplicationXml> 
         </jarModule> 
         <jarModule> 
          <groupId>com.example</groupId> 
          <artifactId>MyWar2</artifactId> 
          <includeInApplicationXml>true</includeInApplicationXml> 
         </jarModule> 
        </modules> 
       </configuration> 
      </execution> 
      <execution> 
       <id>P2</id> 
       <goals> 
        <goal>ear</goal> 
        <goal>generate-application-xml</goal> 
       </goals> 
       <configuration> 
        <workDirectory>target/P2</workDirectory> 
        <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir> 
        <generateApplicationXml>true</generateApplicationXml> 
        <displayName>MyArtifactLibraryP2</displayName> 
        <classifier>P2</classifier> 
        <modules> 
         <jarModule> 
          <groupId>com.example</groupId> 
          <artifactId>MyWar1</artifactId> 
          <includeInApplicationXml>true</includeInApplicationXml> 
         </jarModule> 
         <jarModule> 
          <groupId>com.example</groupId> 
          <artifactId>MyWar2</artifactId> 
          <includeInApplicationXml>true</includeInApplicationXml> 
         </jarModule> 
         <jarModule> 
          <groupId>com.example</groupId> 
          <artifactId>MyWar3</artifactId> 
          <includeInApplicationXml>true</includeInApplicationXml> 
         </jarModule> 
        </modules> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
7

簡單的答案。這是不可能的。問題是基於在這種關係中邪惡的配置文件的使用。

這樣的事情的解決方案是創建一個Maven構建,它能夠產生兩個戰爭文件,這是這個構建的結果。

我假設你有不同的環境,如以下不同的屬性:

. 
|-- pom.xml 
`-- src 
    |-- main 
    | |-- java 
    | |-- resources 
    | |-- environment 
    | | |-- test 
    | | | `-- database.properties 
    | | |-- qa 
    | | | `-- database.properties 
    | | `-- production 
    | |  `-- database.properties 
    | `-- webapp 

這意味着你需要在你的情況下,兩個war文件僅在財產文件的內容有所不同,以創建。在上面有三個環境。

你需要的是一個裝配描述爲每個環境中,如:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 

    <id>test</id> 
    <formats> 
    <format>war</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
    <dependencySet> 
     <unpack>true</unpack> 
     <useProjectArtifact>true</useProjectArtifact> 
    </dependencySet> 
    </dependencySets> 
    <fileSets> 
    <fileSet> 
     <outputDirectory>WEB-INF</outputDirectory> 
     <directory>${basedir}/src/main/environment/test/</directory> 
     <includes> 
     <include>**</include> 
     </includes> 
    </fileSet> 
    </fileSets> 
</assembly> 

而且在這種情況下,適當的執行的Maven的組裝插件類似如下:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>test</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     <configuration> 
      <descriptors> 
      <descriptor>${project.basedir}/src/main/assembly/test.xml</descriptor> 
      </descriptors> 
     </configuration> 
     </execution> 
     <execution> 
     <id>qa</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     <configuration> 
      <descriptors> 
      <descriptor>${project.basedir}/src/main/assembly/qa.xml</descriptor> 
      </descriptors> 
     </configuration> 
     </execution> 
     <execution> 
     <id>production</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     <configuration> 
      <descriptors> 
      <descriptor>${project.basedir}/src/main/assembly/production.xml</descriptor> 
      </descriptors> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

這將導致maven通過單一運行:

mvn package 

它生產三個不同的戰爭文件,其中包含不同的屬性文件或不同內容的文件。 這是一個沒有配置文件,其完美的作品,並部署將被命名爲喜歡的三種不同的戰爭文件的解決方案:

  1. 的artifactId版本,test.war
  2. 的artifactId版本-QA。戰爭
  3. 的artifactId版本,production.war

,這就是你需要解決你的問題的結果。

+0

建議的解決方案可能是某種「簡單」項目(如在你的例子中)的「解決方法」。但是,我認爲這並不能解決真正的問題。我不認爲解決方案是通過完成戰爭插件或耳塞所做的所有工作來實現的。此外,如果我具有調整生成的二進制文件的配置文件屬性,則建議的解決方案可能無法工作。例如,你將如何有條件地測試代碼或用程序集描述符自動生成application.xml?我開始認爲這可能是一個maven/nexus集成問題。 –

+0

問題是你定義爲**真正的問題**。除此之外,這個插件的工作已經完成了。所以它不能替代它。 application.xml的生成已經在那個時候了。您正在撰寫關於個人資料屬性。與環境相關的配置文件屬性是基於原始帖子的錯誤方式。您希望在哪種情況下使用代碼?基本的觀點是生成的戰爭/耳朵不應該依賴於環境。 – khmarbaise

+0

我有一個有兩個配置文件的項目:每個配置文件以不同的方式配置耳塞:配置文件'A'有2個戰爭模塊,配置文件'B'有3個戰爭模塊。在兩個配置文件中,都使用Jibx(使用不同的描述符)進行裝配。忘記工具,¿如果不執行2次ear-plugin,如何生成2個不同的application.xml? –

相關問題