我有一个 Maven 项目,我尝试使用 ~/.m2/settings.xml 从我的代码中提取敏感信息。据我通过mvn -X
命令检查可以看出,可以从中读取文件。这是我的文件:
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<profiles>
<profile>
<activeByDefault>true</activeByDefault>
<id>camera</id>
<properties>
<camera.url>some url</camera.url>
</properties>
</profile>
</profiles>
</settings>
我尝试使用 pom.xml 从代码中的 camera.url 获取值:
<build>
<defaultGoal>install</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<systemPropertyVariables>
<camera.url>${camera.url}</camera.url>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
然后我尝试使用 检索代码中的值System.getProperty("camera.url")
,但这会返回 null。我似乎无法弄清楚我做错了什么。