Is Maven a framework that provides mainly an archetype like domain.controller-view in grails? - maven

I´ve been reading lot about, but since there are several web frameworks that uses Maven for the project, I got confused, so I´m not entirely sure if Maven is an archetype that defines an schema to start developing apps by following good practices, or is just some piece of sdk that converts my code to bytecode. Thanks in advance to anyone who can drag me out of my confusion and gave me the required info. BTW is that rigth to say an archetype is a directory structure?

I am not sure if you are reading enough about maven, Maven is a build system which can help you build your application, manage your dependencies, run your tests, create reports and many other things.
First link in google result is http://maven.apache.org/
Apache Maven is a software project management and comprehension tool.
Based on the concept of a project object model (POM), Maven can manage
a project's build, reporting and documentation from a central piece of
information.
Each application has many dependencies and many small tasks that needs to be done before you can run your application, developers define them in a file called POM and that will be a instruction for Maven to build the application. Maven can do pretty much everything other than writing your code. In that sense it is like Genie in the story of Aladdin, you wish for something it will bring it for you.
There is a Grails maven plugin that can populate Grails project with the same convention that Grails uses. It can work with Grails to execute your commands and many other. More importantly it will manage your dependencies.

Related

The idea behind using maven to compile source code

I am currently starting my adventure with Maven, and I actually don't understand the idea behind using it to automate compilation of my source code. For the time being I am working on small projects with up to 15-20 classes, and 1 main method in the "app" class. Could someone please give me the explanation with examples, when it's necesarry (or recommended) to use build automatation tool to compile the source code and how could I benefit from using it regarding source code compilation?
Thank you very much in advance!
I was looking for different answers and I have a lot of work to do but since I've seen this question, as a Maven fanboy, I couldn't resist anymore and this below is my answer.
First of all, I agree with JF Meier which answered before me, but I think the answer can be improved.
IMO you have to consider Maven not just as a build tool, but as a multi-purpose tool which can help you to do very different things. The best 3, for me are:
Compiler. Obviously. Maven allows you to easily compile giant projects with a lot of submodules, even if some of these modules are interdependent one with each other.
Dependency and repository manager. Maven allows you to automatically download third party software and bind this downlaod to the build. This is immediately understandable if you think to framework or api dependencies from big corps (Apache found., Spark, Spring, Hibernate and so on ...) but it's really powerful in every enterprise context.
Example: you have a Maven project (let's say project A) which manages requests coming from a webservice and provides responses. This Maven project relys on another Maven project (let's say project B) which actually generates webservice jar and uploads it to a company repository. Well, when you have to add a field or a method to the webservice you just have to implements new software in project B, upload it the repo and change the version in Maven poms in both project A and B. Voilà: now EVERY developer of the company just have to "mvn clean install" project A to have the new version.
Sources and code automatic generator. Since Maven 2.x are available a lot of plugins (from Apache found. and others) which allow you to generate code and sources (tipically xml files) starting from little to none implementations.
Example 1: CXF plugin is commonly used to generate java classes from xml or xsd files.
Example 2: JAXWS plugin is commonly used to generate wsdl from SOAP webservice implementations or implementation starting from wsdl file.
Do you feel the power now?
-Andrea
The question is not very specific, but I will try to answer.
Usually, you want your source code to end up in a jar or war, so that you can use it as a library or run it somewhere (e.g. on an application server).
Maven not only compiles the classes you have and creates the final artifact (jar, war), but also handles your dependencies, e.g. the libraries your project depends upon.

Edit Java source code before compile

I am new to gradle. I am looking forward to migrating from maven to gradle.
I had few requirements:
Existing project is maven based, and is generating a fat jar/uber jar. I am planning to split this into multiple projects, and creating smaller/thinner jars/libraries
I am currently evaluating the Multi-project Build support.
I have to also edit the Java source code, automatically, like making the java source modifications based on certain conditions
Publish the project as maven based, as other projects which need these split-up jars are still maven based.
I suppose Maven plugin can be used for publishing?
Would Gradle be a good, scalable solution for these two requirements which I am looking into currently?
Also please provide some pointers around these two topics.
Gradle has very good multi-project support, far better than Maven's. You can start with this documentation section
You can setup compilation of generated/auto-edited sources as well. Take a look at this forum post, discussing compilation of sources created from database using hbm2dao
You can setup publishing of projects using the Maven plugin. pom.xml files will be generated automatically

What is Workflow management using Maven?

I have only little experience using maven with eclipse. One of the job descriptions which I received has "Workflow management using Maven" as a required skill. What does this mean ? What do they possibly expect?
I think they want you to correct them? :D
I'm not sure what they refer to. I would guess it relates to the developer workflow of creating and delivering software with eclipse (?) and maven.
So setting up a project from scratch is often done from an maven archetype (a project template if you like). A lot of open source frameworks offer archetypes to start with.
For existing projects you would check out the code from version control and import it into eclipse. the m2eclipse plugin is required to do that (but I think its quite common to have it)
Then there is building the software. Which is done through executing maven phases (which will then execute plugins). See maven-phases for more details. Maven phases have default plugins that execute (for example compile will run the compiler plugin).
So your workflow would look like this: you modify the files. compile them, test them, package them, deploy the artifacts into the maven repository. the maven install phase will store the artifacts in you local repository, the maven deploy phase will upload them into the company's repository.
From there the the files are installed. Yet you can use maven plugins to install the software into a application server. That depends on the traditions of the company.
I would not think of workflow as some strict step by step think like BPMN. Development is usually done with huge amounts of personal practices (are tests written in advance or while implementing, and so on).
Hope that will help :)

Compare Maven and Gradle

As I am new to learn either maven or Gradle build tools. Therefore I wonder which one I select to study between maven and Gradle and which one has more requirement and demand in the industry. I want to use these build tools for Spring and Hibernate based projects. Any suggestion would be very helpful.
Thanks
Before this is closed for "not being a good question", I'll get some comments in.
You might want to learn the same thing that most other developers want to learn. Look at the third slide of the following slideware, which shows the results of Zeroturnaround's yearly developer survey. For this set of >2k developers, when asked what technologies they were interested in learning, Gradle was at the top of the list.
You can use either Maven or Gradle to build projects using Spring or Hibernate, but it's useful to point out that both the Spring and Hibernate code bases (not necessarily the applications using them) use Gradle to build their deliverables.
Maven provided the best build solution for quite a few years, but it's difficult to customize a build, and most Maven build scripts are very "noisy". Gradle solves those problems, while providing a smooth migration path from Maven or even Ant.

need some help about maven

we have several projects in our company with many dependencies among them. we have gathered our projects (EJB,Web, Enterprise Application and ...), on a SVN server, now we have difficulties with our projects, because after checking out a project from SVN, we have to waste a long time to gather the required libraries and projects for the checked-out project to build.
i want to some help about that, how the maven technology could help us to easily gather the dependencies and build our projects automatically. we use myeclipse IDE.
moreover i need some help and resources, to learn how to achieve this goal.
any guide and help will be appreciated.
thanks in advance.
Depending on the amount of projects you have, and how complex their build is, switching to Maven can be a hell of a task. It might still be worthwhile, mainly because Maven forces you to do things "the Maven way"1, and that such a "Maven way" is becoming more standard with time: you might end up with a simplified/more standardized build procedure.
If your projects are currently built using ant, chances are that ivy can quite more easily solve your problem of offloading JARs from your VCS system, with a minimal impact to your current build configuration.
Otherwise, if you really think Maven is the right tool for you, I strongly suggest you to have a look at the official tutorial, the POM reference and start playing with simple, self generated projects to start having an idea about how to deal with Maven. Using the archetype:generate mechanism you have access to dozens (hundreds?) of sample projects (archetypes, in Maven jargon) that illustrate you how to deal with different kinds of projects, from simple JAR to more complex ones, maybe leveraging exotic frameworks or products. Have a look at the generated POM for such projects and try to understand how it works.
Integration with Eclipse is achieved via two different plugins. I'm not using Eclipse anymore since quite a while, but I think m2eclipse is still probably the best one to start with.
1- WARN: his is one of the things people coming to Maven heavily dislike more often than not

Resources