2013-01-13 58 views
0

我有一個多模塊project其中我試圖設置許可證插件來管理所有許可證。這裏是項目設置:帶許可證插件的Maven多模塊項目

─── transfuse-project 
    ├── examples 
    │   ├── helloAndroid 
    │   │   ├── pom.xml 
    │   │   ├── ... 
    │   ├── integrationTest 
    │   │   ├── pom.xml 
    │   │   ├── ... 
    │   ├── pom.xml 
    │   └── ... 
    ├── transfuse 
    │   ├── pom.xml 
    │   ├── ... 
    ├── transfuse-api 
    │   ├── pom.xml 
    │   ├── ... 
    ├── NOTICE 
    └── pom.xml 

每個pom.xml繼承自transfuse-project pom.xml。在pom.xml中我已經建立了許可證插件,該通知適用於相關文件的項目:如果我直接建在根(輸血項目)的

 <plugin> 
      <groupId>com.mycila.maven-license-plugin</groupId> 
      <artifactId>maven-license-plugin</artifactId> 
      <version>1.9.0</version> 
      <configuration> 
       <header>NOTICE</header> 
       <includes> 
        <include>**/*.java</include> 
        <include>**/*.xml</include> 
       </includes> 
       <excludes> 
        <exclude>**/.*/**</exclude> 
        <exclude>target/**</exclude> 
        <exclude>**/AndroidManifest.xml</exclude> 
       </excludes> 
       <properties> 
        <year>2013</year> 
        <name>John Ericksen</name> 
       </properties> 
       <useDefaultExcludes>true</useDefaultExcludes> 
       <strictCheck>true</strictCheck> 
      </configuration> 
      <executions> 
       <execution> 
        <id>check-headers</id> 
        <phase>verify</phase> 
        <goals> 
         <goal>check</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

這種配置工作。直接構建integrationTest示例或api時會出現問題。 Maven的找不到我的項目的根目錄中提供的通知文件:

[ERROR] Failed to execute goal com.mycila.maven-license-plugin:maven-license-plugin:1.9.0:check (check-headers) on project transfuse-api: Some files do not have the expected license header -> [Help 1] 

更糟糕的是,它發現另一個依賴的通知文件。如果我在子模塊中運行mvn license:format,它會將所有模塊的標題替換爲依賴的通知文件。

我相信我可以在每個子模塊中添加一個NOTICE文件來解決這個問題,併爲每個子模塊配置自己的許可證插件,但是如果可能的話,我想避免這種重複。是否有一些配置或設置可用於我的項目設置?

回答

1

嘗試使用

<header>${basedir}/NOTICE</header> 

使用的絕對路徑如果這不起作用,嘗試set a property to and in the parent module's basedir並使用它:

<header>${main.basedir}/NOTICE</header> 

第三個選項是在設置屬性運行時間:

mvn clean install -Dmain.basedir=path/to/main/basedir 

編輯:

好吧,整個其他選項是在許可證插件之前執行maven-dependency-plugin。但是,你必須確保家長重視的通知(與maven-assembly-plugin plugin

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <version>2.6</version> 
     <executions> 
      <execution> 
      <id>unpack-parent</id> 
      <phase>verify</phase> 
      <goals> 
       <goal>unpack</goal> 
      </goals> 
      <configuration> 
       <artifactItems> 
       <artifactItem> 
        <groupId>parent</groupId> 
        <artifactId>parent</artifactId> 
        <version>parent</version> 
        <type>pom</type> 
        <overWrite>false</overWrite> 
        <outputDirectory>${project.build.directory}/license</outputDirectory> 
        <includes>NOTICE</includes> 
       </artifactItem> 
       </artifactItems> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 

header變化然後在:

<header>${project.build.directory}/license/NOTICE</header> 

EDIT2:

我穿過發現,行家來-插入。我想這可能是工作:

<plugin> 
    <groupId>com.github.goldin</groupId> 
    <artifactId>find-maven-plugin</artifactId> 
    <version>0.2.5</version> 
    <executions> 
     <execution> 
      <id>find-notice-file</id> 
      <goals> 
       <goal>find</goal> 
      </goals> 
      <phase>validate</phase> 
      <configuration> 
       <propertyName>notice.file</propertyName> 
       <file>NOTICE</file> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
+0

啊,我想這一點。從根部開始工作,但構建任何子模塊都失敗。 –

+0

編輯我的答案......它會工作,但它是額外的樣板 – asgoth

+0

賓果,第二個選項工作。謝謝您的幫助。 –

0

實際上,有這樣做更簡單的方法。只需在配置中將aggregate標記設置爲true即可。下面是完整的maven-license-plugin定義:

<plugin> 
    <groupId>com.mycila.maven-license-plugin</groupId> 
    <artifactId>maven-license-plugin</artifactId> 
    <version>1.10.b1</version> 
    <configuration> 
     <header>etc/header.txt</header> 
     <aggregate>true</aggregate> 
     <includes> 
      <include>**/*.java</include> 
     </includes> 
    </configuration> 
</plugin> 

然後你只需要有一個父根目錄稱爲etc/header.txtheader.txt文件。

+0

構建父代時適用,但不適用於您自行構建單個模塊時。 –

0

試試你的例子與設置此兩個配置屬性:

<plugin> 
    <groupId>com.mycila</groupId> 
    <artifactId>license-maven-plugin</artifactId> 
    <version>2.7</version> 
    <configuration> 
    <header>/NOTICE</header> 
    <aggregate>true</aggregate> 
    </configuration> 
</plugin>