簡體   English   中英

Maven 扁平化插件不起作用並不能替代我的版本屬性

[英]Maven flatten plugin not working does not substitute my version property

出於某種原因,當我執行 mvn install 並檢查我的本地 repo 並查看那里的 pom 時,我沒有看到 version 變量被替換為值。

我在屬性中使用帶有版本的pom

<properties>
    <maven.javadoc.skip>true</maven.javadoc.skip>
    <revision>19.3.29</revision>
</properties>

它還包含 flatten 插件條目:

          <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.2.2</version> 
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>resolveCiFriendliesOnly</flattenMode>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

pom 使用 ${revision} 作為版本值和 ${project.version} 作為 maven推薦的依賴項的值:

<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">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>analysisModule</artifactId>
    <version>${revision}</version>
    <parent>
        <groupId>com.mycompany.analysis</groupId>
        <version>1.0.0</version>
        <artifactId>autoav</artifactId>
        <relativePath>../autoAV</relativePath>
    </parent>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    <dependencies>
      <dependency>
        <groupId>com.mycompany.analysis</groupId>
        <artifactId>analysisCore</artifactId>
        <version>${project.version}</version>
      </dependency>
    </dependencies>
</project>

在我“mvn install”之后查看本地 repo pom xml:

<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">
        <modelVersion>4.0.0</modelVersion>
        <artifactId>analysisJdbc</artifactId>
        <version>${revision}</version>
        <description>analysis of jdbc sources</description>
        <parent>
                <groupId>com.mycompany.analysis</groupId>
                <version>1.0.0</version>
                <artifactId>autoav</artifactId>
                <relativePath>../autoAV</relativePath>
        </parent>
        <build>
                <resources>
                        <resource>
                                <directory>src/main/resources</directory>
                                <filtering>true</filtering>
                        </resource>
                </resources>
        </build>
        <dependencies>
                <dependency>
                        <groupId>com.mycompany.analysis</groupId>
                        <artifactId>analysisCore</artifactId>
                        <version>${project.version}</version>
                </dependency>
...
</project>

${revision}${project.version}不應該替換為實際數字嗎? 這不是使用 flatten 插件的全部內容嗎?

我跟着這個https://www.mojohaus.org/flatten-maven-plugin/examples/example-central-version.html

添加我的 mvn install 的 output (跳過測試)(maven 版本 3.3.9):

02:12:03 :/code/thedrs/gitrepos/analysis/analysis/analysisJdbc  (main) $ mvn install  -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building analysisJdbc 19.3.30
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ analysisJdbc ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ analysisJdbc ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ analysisJdbc ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ analysisJdbc ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ analysisJdbc ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ analysisJdbc ---
[INFO] Building jar: /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/target/analysisJdbc-19.3.30.jar
[INFO] META-INF/maven/com.mycompany.analysis/analysisJdbc/pom.xml already added, skipping
[INFO] META-INF/maven/com.mycompany.analysis/analysisJdbc/pom.properties already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ analysisJdbc ---
[INFO] Installing /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/target/analysisJdbc-19.3.30.jar to /code/thedrs/.m2/com/mycompany/analysis/analysisJdbc/19.3.30/analysisJdbc-19.3.30.jar
[INFO] Installing /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/pom.xml to /code/thedrs/.m2/com/mycompany/analysis/analysisJdbc/19.3.30/analysisJdbc-19.3.30.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.147 s
[INFO] Finished at: 2020-05-06T02:12:40-07:00
[INFO] Final Memory: 14M/356M
[INFO] ------------------------------------------------------------------------

您需要將插件從<pluginManagement><plugins>移動到<plugins> 或者,您可以將其保留在那里,只需將一個簡短的插件定義(包括 groupId 和 artifactId)添加到<plugins>部分。

<pluginManagement>只是為了預配置版本號和配置。 <pluginManagement>中的插件在構建期間不會運行,除非它們重新出現在<plugins>中。

我已經能夠通過為依賴項創建另一個屬性來實現這一點。 此屬性將具有與${revision}相同的值,並將在生成的 pom 文件中替換。

<properties>
    <revision>19.3.29</revision>
    <my-lib.version>${revision}</my-lib.version>
</properties>

然后,不要在依賴項中使用${project.version} ,而是使用您的屬性:

<dependency>
    <groupId>com.mycompany.analysis</groupId>
    <artifactId>analysisCore</artifactId>
    <version>${my-lib.version}</version>
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM