如何向asciidoctor-maven-plugin传递环境变量?
步骤1:声明高版本PlantUML依赖
在POM的dependencies节点中添加符合版本要求的PlantUML依赖:
<dependency> <groupId>net.sourceforge.plantuml</groupId> <artifactId>plantuml</artifactId> <version>1.2024.3</version> <scope>provided</scope> </dependency>
步骤2:配置maven-dependency-plugin导出Jar路径
使用maven-dependency-plugin的properties目标,将PlantUML的本地Jar路径导出为Maven属性:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.6.1</version> <executions> <execution> <id>get-plantuml-jar-path</id> <phase>process-resources</phase> <goals> <goal>properties</goal> </goals> </execution> </executions> </plugin>
执行后会自动生成名为net.sourceforge.plantuml:plantuml:jar的属性,值为PlantUML Jar包在本地Maven仓库的绝对路径。
步骤3:在asciidoctor-maven-plugin中注入环境变量
asciidoctor-maven-plugin原生支持environmentVariables配置项,可以直接向插件运行时注入环境变量,不需要额外的第三方插件:
<plugin> <groupId>org.asciidoctor</groupId> <artifactId>asciidoctor-maven-plugin</artifactId> <version>2.2.4</version> <!-- 保持你原有的其他配置不变,比如executions、dependencies等 --> <configuration> <!-- 你原有的其他配置,比如sourceDirectory、outputDirectory、attributes等 --> <environmentVariables> <DIAGRAM_PLANTUML_CLASSPATH>${net.sourceforge.plantuml:plantuml:jar}</DIAGRAM_PLANTUML_CLASSPATH> </environmentVariables> </configuration> </plugin>
原配置失效原因说明
你之前使用properties-maven-plugin的set-system-properties目标设置的是JVM系统属性,和操作系统环境变量是完全独立的两类配置,而asciidoctor-diagram读取的是环境变量,因此不会生效。
内容的提问来源于stack exchange,提问作者Riduidel
相关产品推荐
相关产品推荐

