XML – Is there a way to add a dependency from the command line to Maven POM?

Is there a command or Maven plugin that I can use to add dependencies to the POM from the command line?

For example, I want to type the following:

mvn lazy:add-dependency -DgroupId=com.mycompany -DartifactId=derp -Dversion =1.0

and let it modify the dependency part of the POM in the current directory:


... other dependencies .. .

com.mycompany
derp
1.0

Adding the above XML external commands is also possible, but I prefer commands that do not require me to write an XSL style sheet.

Not sure if you have solved this problem, but I have done similar things with xsltproc in the past (I know you said don’t use a , But I never found another way).

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.informat ik.hu-berlin.de/~obecker/XSLT/merge/merge.xslt

Then call the Bash function:

merge_xml $PROJECT_ROOT/content/ pom.xml $PROJECT_ROOT/content/pom.xml << EOF 



com.company
my-artifact
1.0-SNAPSHOT< /version>
jar



EOF

Is there a command or Maven plugin I can use to add dependencies to the POM from the command line?

For example, I want to type the following:

mvn lazy:add-dependency -DgroupId=com.mycompany -DartifactId=derp -Dversion =1.0

and let it modify the dependency part of the POM in the current directory:


... other dependencies .. .

com.mycompany
derp
1.0

Adding the above XML external commands is also possible, but I prefer commands that do not require me to write an XSL style sheet.

Not sure if you solved this problem, but I have done similar things with xsltproc in the past (I know you said not to use one, but I never found another way).

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 call Bas h function:

merge_xml $PROJECT_ROOT/content/pom.xml $PROJECT_ROOT/content/pom.xml << EOF 



com.company
my-artifact
1.0-SNAPSHOT
jar



EOF

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 6016 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.