How to stop Maven renaming installed jars - maven-2

I am installing to Maven repository our internal files using mvn install:install command. All Jars installed in such way have version name added automatically as a suffix. Since we have many batch scripts with the Jars names it is very inconvenient for us. How this auto-renaming can be switched off?

You can't. Dependency resolution in Maven works because Maven has conventions and the naming of artifacts is one of them. So you can't turn off the way maven install artifacts (and you actually don't want to).
The common way to handle scripts (bat/sh) is to put them in your source tree (e.g. in src/main/bin) and to create a distribution of your project with the assembly plugin. When building your assembly, you can rename artifacts, filter distribution files, etc. That would be the right place to do such kind of things.

it's tempting to want to remove the version number, but I'd recommend keeping it on if at all possible.
Instead of removing the version numbers, maybe you could use Maven's resource filtering capability to manage your batch scripts? Maven can manage your batch scripts by replacing placeholders such as ${project.version} inside the bat script with the current version number from the pom.xml. That way you can ensure that the batch script is running the correct (expected) version of the code.
You could probably force maven to deploy a jar without a version, but if you do so, you lose some of the main benefits of having Maven manage your build in the first place, imo. For example, just yesterday I was asked to maintain a java project not managed by maven with a bunch of non-versioned jar files inside a lib directory. There's no way to know where any of the jars came from.
It might be a little bit of a headache up front, but if you're using maven, you might as well jump in 100% (again, from my experience).

Related

Using Hive in a maven project

I have a project that I am migrating from ant to maven. The project makes use of a lightly-customized Hive build. I figured I would just import this build into our internal maven repo and list it as a dependency in the project's pom file. The problem I'm running into is that the Hive build just generates a bunch of jars in build/dist/lib. Some of these are the core Hive jars themselves and some are jars that Hive depends on. What's the best way to deal with these? Should I put all the core hive jars into our internal repo and just deal with undocumented dependencies in the new project's pom file? Or just jar up everything as a jar of jars and deploy that to the repo? Would that approach even work? Kind of a maven newbie still, thanks for any help.
You should create a POM for your modified Hive build, and deploy it to your internal artifact repo along with the jar. This POM should specify any dependencies (i.e., those other jars). If some of those are also custom versions, you should create POMs for those as well, otherwise just use the standard public groupId/artifactId. This is the Maven way. Note that you don't necessarily need to use the POM for building Hive, just during deployment.
Why you should do this:
If you don't specify the dependencies correctly, you might run into issues when someone forgets to include the full set of dependencies in their project, or specifies the wrong version for one of them
If you create a jar of jars, you might run into issues when someone tries to use the custom Hive "uber jar" as well as a different version of one of those dependencies at the same time. You'll end up with multiple versions of the overlapping classes in the classpath.
The best thing for Maven is always if you tell it everything that is going on. Don't try to tell it what you think it wants to hear.

Problems with Maven 2

I recently started to use Maven2 in one of my Java web application projects. Now I had many issues with it, some times project fails to build for no apparent reason and then it suddenly starts to work when nothing was done at all to project. Or some times our project members must delete project from their harddrive and download project again from SVN. There seems to be many very odd bugs in Maven in eclipse, but there some issues I would like know if it is possible to solve this issues.
1) I have understood that Maven2 should be able to get dependencies for added jars, but when I add a new dependency in Eclipse, it fails when I build it, it says dependecies are missing. How can I make maven to download those missing dependecies automatically?
2) I have Tuckey UrlRewrite Filter in use, but public repositories have only old version of this dependecy, so when I use this old version (3.1 when I need 3.2). How can I include this to project? We have many programmers in this project, so setting up local repository would mean that all our programmers would have to install that local repository.
Now I had many issues with it, some times project fails to build for no apparent reason and then it suddenly starts to work when nothing was done at all to project. (...)
Ok and what is the point of this free rant? I use Maven and my builds are 100% reproducible, there are well known practices to follow to achieve this. Maybe you're just not following them. Anyway if you're not happy with it, what can I say, don't use it.
I have understood that Maven2 should be able to get dependencies for added jars, but when I add a new dependency in Eclipse, it fails when I build it, it says dependencies are missing. How can I make maven to download those missing dependencies automatically?
I think you misunderstood, Eclipse won't guess what Maven coordinates to add if you don't provide the required informations for them. Dependencies must be declared in the POM, either by editing the POM manually or by using m2eclipse wizards.
And if this is what you did (and if I misunderstood the question) then please provide the <dependency> declaration and the exact error trace.
I have Tuckey UrlRewrite Filter in use, but public repositories have only old version of this dependecy, so when I use this old version (3.1 when I need 3.2). How can I include this to project? We have many programmers in this project, so setting up local repository would mean that all our programmers would have to install that local repository.
This question has already been asked several times, see for example Maven, how to add additional libs not available in repo where I suggest two possible solutions (use a corporate repository like Nexus or a "file-based" repository, the former suggestion being the preferred one for a long term solution).

Maven: Variables are not replaced in installed and deployed POM

We have been trying to migrate our multi-module projects to maven. I have been struggling with the maven install plugin bug "http://jira.codehaus.org/browse/MNG-2971". I have written a Java program which can find and replace the expressions using my settings.xml and POM in my local repository view.
As a result all of my parent POM's are having a additional phase in the build process. What i'm doing is that i have attached a goal which will run my Java program during "validate" phase.
I think this is a not a good idea instead i would have asked individuals to run the program on their local repository on their own.
What i'm asking here is that the best way to work around the "install" plugin issue (MNG-2971).
I searched through the net but i could not locate such work around.
Well, I didn't try it because I'm not using properties from the settings.xml but the issue has a work around in the comments.

Sample Ant project with all the 'features' of Maven?

The past week or two I've been studying Maven, and I like it, but there are just a few things that I require Ant tasks for, rather than Maven's complicated and scarcely-documented POM file. However, I believe Maven has a great folder structure going for it, and I like that it natively supports tests, packages the project into a jar by default, and supports a 'resources' folder, from which everything is directly copied into the jar file.
Is there a sample Ant project out there that does the same sort of thing but with an Ant build.xml script? I want the placeholder folders and hello world app and test, just like Maven does when you first create a project from its default archetype:create goal (as demonstrated in the Maven in 5 Minutes page). Or, is there an even better Ant sample project out there that does more or suggests a better folder layout?
If no such thing exists, perhaps someone can help create it in a nice detailed answer? I would be willing to host a permanently-available zip file for anyone who finds this question in the future.
mvn archetype:create
mvn ant:ant
http://maven.apache.org/plugins/maven-ant-plugin/usage.html
... but if there are really "just a few things", you may want to check out the AntRun plugin instead. I'm not trying to sell you on Maven, believe me, but since it's not clear exactly what is stopping you from trying it with your project, I guess I'm suggesting you try to push the issue a little harder.
Refer this: Why you should use the Maven Ant Tasks instead of Maven or Ivy
I also wouldn't recommend Ivy, reasons at the link above.
Quoting the Maven - Frequently Asked Technical Questions and more precisely:
How can I use Maven features in an Ant build?
The Maven Ant Tasks allow many of the
features of Maven, such as dependency
management and repository deployment,
to be used in an Ant build.
Refer to the installation page and the usage page for instructions for installing and using the Maven Ant Tasks respectively. You'll find many links to samples in the usage page and a build.xml showing most of the features in action.
An alternative (direct competitor?) to Maven Ant Tasks would be Apache Ivy.
PS: While it's definitely a good idea to adopt maven standards, even partially, I'd really think about it twice before to drop Maven (but I live in the Maven jungle for a while now - and I like it - so I'm biased).

Should I migrate from Ant to Maven?

I am working on a fairly large project (with a number of modules, a bunch of external libraries etc.) and we are now considering switching from Ant to Maven. I understand the differences between the two, but I am not convinced that it is really worth spending time converting the project layout, setting up all the dependencies, teaching developers and configuration managers doing things "the new way" etc.
There are a lot of resources on the web describing how to migrate from Ant to Maven, but I haven't found that many that say why :-)
Before changing your build system, ask yourself (and the group) why you're changing? If you're changing just because Maven is the "new thing", don't. If you actually see a technical reason to migrate, do it.
In general, unless there's a major compelling reason to do so (new capabilities or much simpler management), I'd say stay with what you have for the current project, but consider Maven for future projects.
Have you read chapter 1 of "Maven, the definitive guide"? In particular, 1.7 Comparing Maven with Ant has an interesting discussion.
I agree with the other answers that advise caution. Maven has strong points, but nothing that can't be done by an Ant build process:
dependency management: Ant has the Ivy subproject, which can interact with Maven repositories.
convention over configuration: you can also do that with Ant, it's just a matter of establishing the rules and enforcing them.
build lifecycle: same as above, you can enforce a convention over the tasks exposed by each build.
build logic reuse (Maven plugins): you can also achieve that in Ant with macrodefs and task libraries.
The thing is, with Maven you get these features out-of-the-box, while with Ant you need a rock-solid build, a very strict set of rules and a way to enforce them (for instance, make sure that everyone follows the conventions when they create a new subproject, that they reuse the existing blocks instead of doing everything from scratch, etc.).
Personally, I would see how well the existing process addresses the issues above: how are dependencies managed, is there a central repository? Are the project structures uniform (when I checkout a project I don't know, how long does it take to figure out how to build it)? Is there some form of build logic reuse, or does each project reinvent the wheel? Which of these features are needed?
Then I would try to balance the cost of adding the missing features to the existing Ant script, against the cost of migrating to Maven (if you don't know Maven, that also includes the cost of learning it).
In any case, I suggest you build a small Maven prototype (5 to 10 projects) illustrating the common cases in your build. You can test a lot of Maven's features with dummy projects containing little java logic (use the archetype plugin to generate them).
Before Maven we were checking dependency libraries (typically third-party, open source variety) into source control - so that we could insure our components compiled and got packaged with the precise versions intended.
Now with Maven in place, we're relying on artifact repositories to hold those versions and we let our pom.xml dependency declarations be the official means of defining version dependencies. This has proven to be a simplifying approach that makes project organization in version control repositories (and their Hudson build projects) much easier to devise. Our local artifact repository is under backup policy along with our source control repositories. It's nice to use the Maven tools to go and search and specify a needed library version. We also use parent pom files to specify dependencies that other project poms inherit by default. So if you want all projects to use the same log4j version, then that is specified in one place in the parent pom file. (But any project can at anytime override and specify a specific version instead of just accepting the default from the parent pom.)
Here is the secret to a successful adoption of Maven:
Use Maven project build approach for
your new greenfield projects
Modify existing legacy projects that
use ant build.xml files to incorporate Maven task
for managing depenedencies (a hybrid
approach)
The benefit is that you can then get all of your projects under Maven dependency management, which is of course it's greatest benefit.
The nice thing about the Maven task for ant, where you specify all dependencies in a pom.xml file, is that it involves just modest modification of the existing ant build.xml file to incorporate Maven for this. From the ant file's perspective, Maven is just a means for defining classpath definitions, which are subsequently used by the various ant build task.
The Maven scope classifier of dependencies can be utilized when defining classpaths such that a suitable classpath can be set for compiling, running unit test, packaging, et al. Other definitions in the pom can also be accessed as ant property definitions.
A lot of existing ant build files are rather complex. It can be a formidable undertaking to convert such projects to a full Maven build process. This hybrid approach of having Maven manage all the dependencies and leave the bulk of the ant build.xml file as is, is most pragmatic.
First, like I'm sure a lot of people will mention, Ant and Maven are not exactly intended to solve the same goals. Since you said you understand what each provides, I won't get into the details of that, so suffice it to say that Ant lets you define the details of how to build individual components, while Maven manages the dependencies between components plus Maven lets you define a complete project build cycle from compile through test and deploy in a programmatic way.
I've used Maven on a couple projects in the past, and I just started using it on another one recently. There are plenty of articles on the net that compare Ant and Maven, so you can look at those, but from my experience, its always worthwhile to consider how you can improve a project. Dependency management and build lifecycle are two important aspects of any large project, and Maven helps in both those areas. If you already have a good build system in place using ant, and your dependencies are kept in a easy to access central location, and you don't plan on extending your build process to include any more advanced build management, then maybe you should stay with what you have.
On the other hand, if you want to use a continuous integration server like hudson or an artifact repository like nexus, then moving your project to maven can really help with build efficiency and automation. You probably would like maven in those situations because the full cycle from dependency to build to artifact can be achieved using those types of tools and you'll be able to better control your builds and releases. On my current project we have many modules and dependencies, like you mention. Migrating to maven so we could use hudson and nexus really helped because we could drop all those 3rd party jars into a nexus repository and stop having to check them into version control or email them around. Also, builds were out of hand because the CM people had a build plan as a document that they would sometimes follow, but making that part of your project (i.e., the pom.xml) defines how you are supposed to build and lets you enforce it. Maven is the glue that holds all of those things together.
In the end, its a matter of how long you expect the project to last, how good your process is now, whether you want to clean up your dependencies, whether you want to enforce your build plan, and whether you want to have the option to use continuous integration and artifact management. If you any of those things, Maven is a strong candidate.