-1

私はmavenプロファイルで初めて手を試しています。私たちのプロジェクトには、いくつかの依存関係があります (1 つは :) を期待します)。ここで、すべての依存関係が「提供」として「スコープ」を持つプロファイルを作成します。

<scope>provided</scope>したがって、スコープの有無にかかわらず、2 つのプロファイルがあり ます。

私の問題は、複数のプロファイルで pom.xml を作成しているときに、多くの行が繰り返されることです。基本的に、両方のプロファイルの依存関係セクションに同じ行セットがありますが、例外は次のとおりです。<scope>provided</scope>

このファイルを短くする方法を見つけようとしています。これを達成する方法を探しています。私は良い解決策を見つけていません。ここに質問を投稿してください。誰かがこれに遭遇し、ここで私を助けてくれることを願っています.

これは私の pom.xml が現在どのように見えるかです: 行を短くする方法はありますか? 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">
    <parent>
        <artifactId>steel-thread</artifactId>
        <groupId>com.securityx</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>feature-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <junit.version>4.11</junit.version>
        <joda.time.version>2.3</joda.time.version>
        <joda.convert.version>1.6</joda.convert.version>
        <log4j.version>1.2.16</log4j.version>
        <guava.version>16.0.1</guava.version>
        <hbase.version>0.98.6-cdh5.2.1</hbase.version>
        <solr.version>4.4.0-cdh5.2.1</solr.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.apache.hbase</groupId>
                    <artifactId>hbase-client</artifactId>
                    <version>${hbase.version}</version>
                </dependency>
                <dependency>
                    <groupId>joda-time</groupId>
                    <artifactId>joda-time</artifactId>
                    <version>${joda.time.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.joda</groupId>
                    <artifactId>joda-convert</artifactId>
                    <version>${joda.convert.version}</version>
                </dependency>
            </dependencies>    
        </profile>
        <profile>
            <id>prod</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.hbase</groupId>
                    <artifactId>hbase-client</artifactId>
                    <version>${hbase.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-log4j12</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>log4j</groupId>
                            <artifactId>log4j</artifactId>
                        </exclusion>
                    </exclusions>
                    <scope>provided</scope>
                </dependency>

                <dependency>
                    <groupId>joda-time</groupId>
                    <artifactId>joda-time</artifactId>
                    <version>${joda.time.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.joda</groupId>
                    <artifactId>joda-convert</artifactId>
                    <version>${joda.convert.version}</version>
                    <scope>provided</scope>
                </dependency>

            </dependencies>

        </profile>
    </profiles>

    <build>
        <!--<sourceDirectory>src/main/scala</sourceDirectory>-->
        <!--<testSourceDirectory>src/test/scala</testSourceDirectory>-->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.scala-tools</groupId>
                    <artifactId>maven-scala-plugin</artifactId>
                    <version>2.15.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>

                <executions>
                    <execution>
                        <id>compile</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <!--<configuration>-->
                <!--<args>-->
                <!--&lt;!&ndash;                        <arg>-make:transitive</arg>&ndash;&gt;-->
                <!--<arg>-g:notailcalls</arg>-->
                <!--&lt;!&ndash; <arg>-feature</arg>    &ndash;&gt;-->
                <!--</args>-->
                <!--</configuration>-->
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <!-- Create a fat jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <!-- Exclude all duplicates -->
                    <filters>
                        <filter>
                            <artifact>org.apache.avro:avro-tools</artifact>
                            <excludes>
                                <exclude>org/slf4j/**</exclude>
                                <exclude>org/apache/avro/**</exclude>
                                <exclude>org/codehaus/jackson/**</exclude>
                                <exclude>com/thoughtworks/**</exclude>
                                <exclude>org/apache/commons/**</exclude>
                                <exclude>org/tukaani/xz/**</exclude>
                                <exclude>org/xerial/snappy/**</exclude>
                                <exclude>javax/servlet/**</exclude>
                                <exclude>org/apache/hadoop/**</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.phoenix:phoenix-client-minimal</artifact>
                            <excludes>
                                <exclude>org/slf4j/**</exclude>
                                <exclude>org/apache/log4j/**</exclude>
                                <exclude>com/google/common/**</exclude>
                                <exclude>org/codehaus/jackson/**</exclude>
                                <exclude>org/apache/avro/**</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <!--  The service main class -->
                                    <mainClass>com.securityx.modelfeature.FeatureService</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Embed the project version in the JAR’s manifest as the Implementation-Version -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.1.6</version>
            </plugin>

        </plugins>
    </build>

</project>
4

1 に答える 1

0

共通の依存関係は、単一のルート レベル<dependencies/>スタンザでプロファイルの外に出ます。これはすべて非常によく文書化されています。

于 2015-02-11T19:55:03.700 に答える