0

例から始めましょう。Factory インターフェイスと Customer クラスがあるとします。

public interface CustomerFactory(){
    Customer create();
}

public class Customer(){
    private String name;

    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }
}

CustomerFactory を必要とする CustmerProject MavenプロジェクトがあるとしますCustomerFactory実装 (もちろんプロジェクトごとに 1 つの実装) でいくつかの Maven プロジェクトを作成したいのですが、 CustmerProjectがこれらすべての実装プロジェクトに依存することは望んでいません。CustmerProjectが依存するCustomerFactoryInterfaceProjectを1 つ作成し、CustomerFactoryImplementationProject の 1 つをCustomerFactoryInterfaceProjectとして配置したいと考えています。これが可能であることは知っていますが、実際にそれを行うにはどうすればよいですか?

PS質問が明確でない場合は、私に尋ねてください。

4

2 に答える 2

1

ArtifactId または CustomerFactoryImplementationProject のバージョンをパラメーター化し、maven プロファイルを使用してビルド中に実装を選択できます。

次の成果物があるとします。

  • お客様
  • 顧客-工場-1
  • 顧客工場-2

そのため、顧客プロジェクトの pom.xml には次のものが必要です。

<dependency>
    <groupId>base</groupId>
    <artifactId>${customer.factory.artifact}</artifact>
    <version>123</version>
</dependency>
....
<profiles>
    <profile>
        <id>customerFactory1</id>
        <properties>
            <customer.factory.artifact>customer-factory-1</customer.factory.artifact>
        </properties>
     </profile>
     <profile>
        <id>customerFactory2</id>
        <properties>
            <customer.factory.artifact>customer-factory-2</customer.factory.artifact>
        </properties>
     </profile>
</profiles>

そして、ビルド中に次のようにプロファイルを選択するだけです。

mvn -P customerFactory2 install

...または実際には、依存ブロックを直接プロファイルできます。

<profiles>
    <profile>
        <id>customerFactory1</id>
        <dependencies>
             <dependency>
                 <groupId>base</groupId>
                 <artifactId>customer-factory-1</artifact>
                 <version>123</version>
             </dependency>
        </dependencies>
     </profile>
     <profile>
        <id>customerFactory2</id>
        <dependencies>
             <dependency>
                 <groupId>base</groupId>
                 <artifactId>customer-factory-2</artifact>
                 <version>123</version>
             </dependency>
        </dependencies>
     </profile>
</profiles>
于 2013-05-24T09:32:28.913 に答える