如何在打包过程中访问属于当前正在构建的项目的依赖项的文件?

问题描述 投票:0回答:1

场景: 应用程序需要依赖A.jar。

A.jar 有一个 ProGuard 混淆阶段,可生成映射文件 (A-mapping.txt)。

应用程序也变得混乱。

如何在构建过程中将 A-mapping.txt 传递给应用程序?我需要像所有依赖项之间的共享目录之类的东西,我把所有映射文件都放在其中。

我想将 A-mapping.txt 包含在应用程序 ProGuard 配置文件中: -applymapping A-mapping.txt

这可以通过 Maven 实现吗?

java maven proguard
1个回答
0
投票

我会使用

unpack
插件的
maven-dependency
目标。

它的文档在这里: https://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html

对于您的情况,它应该看起来像:

       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>3.6.1</version>
         <executions>
           <execution>
             <id>unpack</id>
             <phase>process-resources</phase> <!-- change to best relevant phase -->
             <goals>
               <goal>unpack</goal>
             </goals>
             <configuration>
               <artifactItems>
                 <artifactItem>
                   <groupId><!-- 'A' groupId--></groupId>
                   <artifactId>A</artifactId>
                   <version><!-- 'A' version--></version>
                   <type>jar</type>
                   <includes>/dir/inside/jar/to/A-mapping.txt</includes>
                 </artifactItem>
                 <!-- you may extract some more artifacts here -->
               </artifactItems>
               <outputDirectory>${project.build.directory}/your/mappings</outputDirectory>
             </configuration>
           </execution>
         </executions>
       </plugin>

您将在

${project.build.directory}/your/mappings
中提取映射文件,以便您可以使用它们在后续 Maven 阶段构建最终应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.