In my pom.xml I have referenced a custom plugin, which is exposing a couple of goals. While I can attach these goals to the various build life-cycle phases, I would like to be able to invoke a set of goals defined in the POM by using my custom alias phase on the command line, such as:
mvn myphase
Is there any way to accomplish this? I would like to avoid modifying my plugin as I need to run some auxiliary operations, which are provided by the antrun plugin.
You want to invoke a custom phase not a goal (changed your question). You have to write your custom lifecycle which will include your custom phase. Do you really want to do that? Have a look at this.
Related
Is there a guide that outlines how to perform each of the following ant tasks using Maven?
http://ant.apache.org/manual/tasklist.html
Is it considered best practice to use Maven for these tasks or just run them in ANT via ant tasks feature.
There is no mapping between ant tasks and "Maven tasks", because Maven doesn't have tasks. Its philosophy is completely different.
Ant is imperative: you tell Ant what to do with a sequence of parameterized tasks.
Maven is descriptive: you describe which kind of project you have, respect a set of conventions (or describe how you broke these conventions, and Maven decides which tasks it must do.
Somewhere there's a table that shows Maven plugins that are analagous to given Ant tasks, but I can't seem to find it. The "Available Plugins" list might help you out.
There is a list of ant-task-to-maven-plugin at the end of this page -> http://maven.apache.org/plugins/maven-antrun-plugin/usage.html
Unfortunately, it only covers a small subset of ant tasks.
I've recently mavenized ant-based project (I really had it with dependency management) and from that experience I had very little need to retain Ant code. The only place I've used antrun plugin was around custom code generation.
I think that it's perfectly fine to delegate some tasks to ant (and sometimes even to scripts) if that's well documented and saves time and maintenance cost.
One other place where I still use antrun is for echoing some environment properties and generic text to a build output, but maybe it's just my ignorance and there is a Maven way for that.
I have a multi-module project. In one of the modules I'm generating classes from wsdl. In the pom of this module I need some properties of another module. (build.directory, outputDirectory etc)
It something like this possible?
${project.parent.module.0.build.directory}
I think I saw the above somewhere. Didn't bother testing it because doing module.0 would mean it's dependent on the order in which modules are declared in the parent pom.
Is there a elegant way of doing what I want?
The proper way to do this is to have a parent. Define the properties in there and then simply use that as the parent in your other modules. That way you can easily share the properties across your modules.
Maven doesn't provide this kind of access. You could use Groovy via GMaven to parse the other pom as XML and get at what you want.
We're trying to migrate from current Ant build to Maven. In the current project, we've different properites files for each of the env say
qa.properties, prod.properties & dev.properties.
The property values present in these files, are used to replace wherever these properties are being referred through config files (present in src\main\resources\config ). The current Ant build process replaces all these properties which are being referred in config files with their corresponding value for the current build env.
I'm somewhat aware of the Profiles concept in maven. However, I'm not able to figure how to achieve this using maven.
Any help would be appreicated.
Thanks,
Prabhjot
There are several ways to implement this but they are all variations around the same features: combine profiles with filtering. A Maven2 multi-environment filter setup shows one way to implement such a setup (a little variation would be to move the filter declaration inside each profile).
See also
9.3. Resource Filtering
I wonder what is the Maven way in my situation.
My application has a bunch of configuration files, let's call them profiles. Each profile configuration file is a *.properties file, that contains keys/values and some comments on these keys/values semantics. The idea is to generate these *.properties to have unified comments in all of them.
My plan is to create a template.properties file that contains something like
#Comments for key1/value1
key1=${key1.value}
#Comments for key2/value2
key2=${key2.value}
and a bunch of files like
#profile_data_1.properties
key1.value=profile_1_key_1_value
key2.value=profile_1_key_2_value
#profile_data_2.properties
key1.value=profile_2_key_1_value
key2.value=profile_2_key_2_value
Then bind to generate-resources phase to create a copy of template.properties per profile_data_, and filter that copy with profile_data_.properties as a filter.
The easiest way is probably to create an ant build file and use antrun plugin. But that is not a Maven way, is it?
Other option is to create a Maven plugin for that tiny task. Somehow, I don't like that idea (plugin deployment is not what I want very much).
Maven does offer filtering of resources that you can combine with Maven profiles (see for example this post) but I'm not sure this will help here. If I understand your needs correctly, you need to loop on a set of input files and to change the name of the output file. And while the first part would be maybe possible using several <execution>, I don't think the second part is doable with the resources plugin.
So if you want to do this in one build, the easiest way would be indeed to use the Maven AntRun plugin and to implement the loop and the processing logic with Ant tasks.
And unless you need to reuse this at several places, I wouldn't encapsulate this logic in a Maven plugin, this would give you much benefits if this is done in a single project, in a unique location.
You can extend the way maven does it's filtering, as maven retrieves it's filtering strategy from the plexus container via dependency injection. So you would have to register a new default strategy. This is heavy stuff and badly documented, but I think it can be done.
Use these URLs as starting point:
http://maven.apache.org/shared/maven-filtering/usage.html
and
http://maven.apache.org/plugins/maven-resources-plugin/
Sean
Is there an Ant equivalent to the 'profile' concept in Maven?
I'd like to be able to specify a different set of targets to build (out of one Ant file) depending on an argument. So in Maven I can specify a profile and then activate it like so: mvn groupId:artifactId:goal -Denvironment=test
So say my build.xml contains:
<target name="profile1">...</>
and
<target name="profile2">...</>
How could I specify at compile time which I want to execute?
You can pass arguments to ant when you invoke it
ant -DProfile=foo
Then ${Profile} will substitute for foo
This is a sucky workaround but it should be able to pass arguments via the command line if that is your goal.
You can read properties from files using the property or loadproperties tasks.
Depending on exactly what you're trying to replicate this might do.
For the first case: "ant profile1". The second case is left as an exercise.
Seriously, the list of targets you want to execute is already an argument to ant. I think you need to make your example a little more explicit.