Michal Aleksander

Greenhorn
+ Follow
since Aug 01, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michal Aleksander

That is a fair point, I will adjust the logic of how my "db.skip.*" properties are handled.

And yeah, I am coming from ant background, so for me most of the things are still easier to achieve with ant than with maven. But as you said, the beauty is there and I am slowly learning to see it.
9 years ago
@Tim, I presume that in your example SQLCODE is an arbitrary variable which is supposed to hold the filename that will then be referenced from within the execution of an "execute" goal of the plugin, right?
9 years ago
Thanks Peter. I would much prefer the approach of leaving the plugin's goal unassigned and simply calling if from the command line, but the issue here is that I have multiple executions for the same "execute" goal (it's the only goal in this plugin) each with different configuration: One for building a DB, one for dropping it and one for populating it with data. The nature of this build forces me to leave the phases separate. I suppose what I am looking for is a way to call a particular execution, something like: "mvn sql:execute:<execution_id> but I have not found a way of doing that.
9 years ago
Answering myself.

What I ended up doing is actually pretty simple.

I declared a property db.skip.create and set it to false in properties section of pom.xml and added
<skip>${db.skip.create} </skip> in the execution section of the mysql maven plugin. The execution is still tied to the initialization phase but will not be invoked, unless db.skip.create is set to false. So, to create the db I use:

mvn initialize -Ddb.skip.create=false;

This is platform independend, external tools don't have to be run and it is driven by maven, so it solves my problem.

I will still leave this unsolved for a day or two, in case someone comes up with a neater solution.

Cheers,
Michal
9 years ago
Hi there,

This is my first post, so, howdy fellow greenhorns! :-)

Now, what I am trying to achieve may seem a bit convoluted and if I am going about this the wrong way - please let me know, I am happy to change the approach.

I have a maven-built webapp (well, it's not quite there yet). I am trying to integrate a creation of a new DB instance into the build itself, but I don't want to bind it to any particular phase (as in, maven lifecycle phase), because it is only intended to be run when the developer wants to get rid of an existing DB and create a new one (not too often, hopefully), on their own local environment. So, it's a slightly different requirement to the very common one, when the new (possibly embedded) database is built and populated before unit/integration testing and then subsequently dropped.

The reason I am trying to do it with maven is to be as platform independend as possible. If I put the SQL into a bash script, some of my teammates (alas, most of them) won't benefit from it much.

Now, I do know there is an sql maven plugin, and I got it working easily, by simply binding it to one of the phases (initialize).

Ok, so the questions are:

- Am I doing it wrong? Are there any "best practices" that apply to this scenario? Am I missing something?
- How can I execute a maven "execution" outside of "phase" scope?

As you can see, I am a maven newbie (started yesterday!), so I may be talking nonsense. Feel free to point that out :-) It may be because I am used to an obvious ant-like flow control in building scripts, and the declarative/IoC style of maven is not quite clear to me yet.

Some resources on similar topics I found:
http://stackoverflow.com/questions/22222808/automatically-creation-of-test-databases-using-maven
http://stackoverflow.com/questions/3166538/how-to-execute-maven-plugin-execution-directly-from-command-line

Thanks.
Michal
9 years ago