MavenXpp3Reader reader = new MavenXpp3Reader();
Model pomModel = reader.read(new FileReader(pomLibFile));
final List<Dependency> dependencies= pomModel.getDependencies();
final List<String> modules= pomModel.getModules();
final List<Profile> profiles = pomModel.getProfiles();
InputStream inputStream = new FileInputStream(new File(pomLibFile));
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, "utf-8");
pomModel.getDependencyManagement();
final Properties properties = new Properties();
properties.load(new FileInputStream(pomProperties));
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
interpolator.addValueSource( new EnvarBasedValueSource() );
interpolator.addValueSource( new PropertiesBasedValueSource( properties ) );
List<String> synonymPrefixes = new ArrayList<String>();
synonymPrefixes.add( "project." );
synonymPrefixes.add( "pom." );
PrefixedValueSourceWrapper modelWrapper = new PrefixedValueSourceWrapper( new ObjectBasedValueSource( pomModel ),synonymPrefixes, true );
interpolator.addValueSource( modelWrapper );
PrefixedValueSourceWrapper pomPropertyWrapper =
new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( pomModel.getProperties() ), synonymPrefixes, true );
interpolator.addValueSource( pomPropertyWrapper );
interpolator.addValueSource( new PropertiesBasedValueSource( properties ) );
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( synonymPrefixes, true );
String serializedPOM = interpolator.interpolate( writer.toString(), recursionInterceptor );
System.out.println("-------- "+serializedPOM);;
参考资料 : http://plexus.codehaus.org/plexus-components/plexus-interpolation/index.html
尽管如果我必须添加多个(未知数量的)依赖项,我仍然陷入困境。