2012-01-02 22 views
12

私のMavenプロジェクトにローカルリポジトリを定義したいと思います。子モジュールのPOMでスーパーPOMベースを取得する方法は?

私はスーパーポームといくつかの子モジュールを持っています。私のファイル構造は次のとおりです。私は定義する私のスーパーポンポンで

/root 
    /repository 
    /child 
     pom.xml 
    pom.xml 

<repository> 
    <id>my-local-repo</id> 
    <url>file://${basedir}/repository</url> 
</repository> 

問題は私の子供のポンポンで、私のスーパーポンポンで定義されたリポジトリは/ルート/子/リポジトリを参照していることです依存関係が見つかりません...

スーパーPOMに相対的なパスを常に定義する方法はありますか?

もしそうでない場合は、問題を解決する最良の方法は何ですか?

+0

だから、リポジトリごとにプロジェクトを作成したいですか?たぶん '$ {project.parent.relativePath}'は解決できます(あなたのすべての子POMに ''を定義する必要があります)。 –

答えて

4

${project.parent.basedir}を実行してください。

また、プロパティのルートのbasedirパスを設定して継承することもできます。親この場合

<properties> 
    <rootPath>${basedir}</rootPath> 
</properties> 

と子で

<repository> 
    <id>my-local-repo</id> 
    <url>file://${rootPath}/repository</url> 
</repository> 
+3

あなたの返信をありがとうが、親pomの$ {basedir}は子pomパスに置き換えられ、$ {project.parent.basedir}は決して –

+2

と解釈されないため、実行されません。プロパティはまず親からマージされ、処理されます。 –

4

でこのような何か、最初にあなたは${project.parent.basedir}を試みることができます。
$ {basedir}変数を使用する代わりに、シンプル(ネイティブ)の方法では完全パス(/ root/...)を使用するか、相対パス(../)を使用します。

私にとっては、この設定をプロパティファイルに外部化するのが最適です。
プロパティ-maven-pluginhttp://mojo.codehaus.org/properties-maven-plugin/plugin-info.html)を使用できます。

このプラグインでは、プロパティファイルで定義されたプロパティは、pom.xml内で定義されたプロパティと同様に読み取ることができます。あなたはこの内容でteams.propertiesという名前のプロパティファイルがある場合は

は:

toronto=raptors 
miami=heat 

があなたのpom.xmlに次のように宣言すると同じようになります:プラグインサイトから

<properties> 
    <toronto>raptors</toronto> 
    <miami>heat</miami> 
</properties> 
0

私はこれをgroovyプラグインで何回も解決しました。 "basepath_marker"という名前のファイルをスーパーpomのディレクトリに追加し、あなたのpomに以下を追加してください。 $ {base-path}のよ​​うにプロパティにアクセスできます。詳細はthis blog postをご参照ください。

例:

... 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.gmaven</groupId> 
      <artifactId>groovy-maven-plugin</artifactId> 
      <executions> 
       <!-- set absolute base path from super pom --> 
       <execution> 
        <id>find-basepath</id> 
        <phase>validate</phase> 
        <goals> 
         <goal>execute</goal> 
        </goals> 
        <configuration> 
         <source> 
          <![CDATA[ 
           import java.io.File; 
           log.info('## define projects super pom absolute path through basepath_marker') 
           String p = "basepath_marker"; 
           File f = null; 
           if(p != null) { 
            def _max_child_poms = 0 
            while(_max_child_poms++ < 5) { 
             f = new File(p); 
             if(f.exists()) { 
              break; 
             } 
             p = "../" + p;         
            } 
           } 
           if(f != null) { 
            String basePath = f.getCanonicalPath(); 
            basePath = basePath.substring(0, basePath.lastIndexOf(File.separator)); 
            project.properties['base-path'] = basePath.replace('\\' , '/'); 
            log.info(' - used base path = ' + project.properties['base-path']); 
           } else { 
            log.error('Could not find basepath_marker marker file!'); 
            System.stop(0); 
           } 
          ]]> 
         </source> 
        </configuration> 
       </execution>      
      </executions> 
     </plugin> 
    </plugins> 
</build> 
... 
関連する問題