Skip to content
Advertisement

Setting maven build property programmatically in Java without writing a plugin?

I need to define some additional properties to be used in maven plugin configurations (pom.xml). Is this possible in a programmatic way using Java code? The exec:java goal seems to run code directly inside the maven process. Is there any way to exploit this?

I need the project basedir property with forward slashes such that I can use it in a wildfly CLI script resource to set up a WildFly database resource. The database resource should point to an absolute path, ie. build output directory or basedir.

This is the script:

/subsystem=datasources/data-source=MyDS:add(
   jndi-name=java:jboss/datasources/MyDS,
   driver-name=h2,connection-url="jdbc:h2:file:${basedir}/db;
   TRACE_LEVEL_SYSTEM_OUT=0",user-name=sa,
   validate-on-match=true,background-validation=false,
   driver-class=org.h2.Driver)

Advertisement

Answer

There is no easy way to do that, afaik. Maven is a great tool as long as you respect the way it works, if you don’t you’re headed for trouble. Perhaps you could add some more details to your question, so we could understand what you really need.

What I can think of is to use the GMaven Plugin or the AntRun plugin to embed either Groovy or ant code in your pom.xml. Both of them can interact with the project object, which means they can manipulate properties. But it’s not going to be easy, and your mileage may vary.

Advertisement