Is there a command or Maven plugin I can use to add a dependency to a POM from the command line?
For example, I want to type something like:
mvn lazy:add-dependency -DgroupId=com.mycompany -DartifactId=derp -Dversion=1.0
and have it modify the dependencies section of the POM in the current directory:
<dependencies>
... other dependencies ...
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>derp</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
An external command to add the above XML would also work, but I'd prefer one that doesn't require me to write an XSL stylesheet.
Not sure if you ever solved this, but I have done something similar in the past with xsltproc ( I Know you said not to use one, but I never found another way of doing it).
function merge_xml ()
{
TEMP_XML1="some-temp-file1.xml"
TEMP_XML2="some-temp-file2.xml"
cat > $TEMP_XML1
cp $1 $TEMP_XML2
echo "Merging XML stream from $1 into $2" >&2
xsltproc --stringparam with "$TEMP_XML1" merge.xslt "$TEMP_XML2" | tidy -xml -indent -quiet -wrap 500 -output $2
}
merge.xslt can be found here http://www2.informatik.hu-berlin.de/~obecker/XSLT/merge/merge.xslt
Then to call the Bash function:
merge_xml $PROJECT_ROOT/content/pom.xml $PROJECT_ROOT/content/pom.xml << EOF
<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/maven-v4_0_0.xsd">
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>jar</classifier>
</dependency>
</dependencies>
</project>
EOF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With