Maven
1. What are the aspects Maven manages?
Answer: Build, Documentation, Reporting, Dependencies, SCMs, Releases, Distribution.
2. What is a Maven Arch-type?
Answer: An arch-type is defined as an original model or pattern from which all other things of the same kind are made. In Maven, an arch-type is a template of a project which is combined with some user input to get the desired outcome.
3. What is the command to create a new project based on an archtype?
Answer: mvn archetype:generate
4. What makes up an arch-type?
Answer: Archtypes are packaged up in Jar file and they consist of the archtype metadata which describes the content of the archtype and a set of Velocity templates which make up a prototype project.
5. What is POM?
Answer: A Project object Model or POM is the fundamental unit of work in Maven. It is an xml file that contains information about the project and configuration details used to build a project by Maven. It contains default value for most projects. Like, the build directory is ‘target’.
6. Name the build, source and test source directory for POM in Maven.
Answer: build=target, source=src/main/java,test=src/main/test.
7. How do you know the version of mvn you are using?
Answer: mvn --version
8. Name the 3 build lifecycle of Maven
Answer: default, clean and site.
9. Name default phases of a build lifecycle in Maven.
Answer: validate, compile, test, package, integration test, verify, install deploy.
10. What would this command do “mvn clean dependency:copy-dependencies package” ?
Answer: This command will clean the project, copy the dependencies and execute all phases up to and including project.
11. What is Maven?
Answer: Maven is an attempt to apply patterns to a project’s build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool.
12. Can Installation and user configuration be used to add shared project information?
Answer: No. For this, you should have your projects inherit from a company-wide parent pom.xml
13. How many artifacts are downloaded at a time from different groups by default?
Answer: 5. To only download single artifacts at a time, do
mvn –Dmaven.artifact.thread=1 clean install
To set this option permanently use MAVEN_OPTS environment variable to -Dmaven.artifact.threads=3
14. How do you compile your source code in Maven?
Answer: Change to the directory where pom.xml is created by archetype:create and execute the following command to compile your application sources.
mvn compile
15. When you compile a Maven project, where do you find the class files?
Answer: ${basedir}/target/classes/
16. What command should you use if you simply want to compile your test sources ( but not execute the tests?
Answer: mvn test-compile
17. How do you compile my test sources and run my unit tests?
Answer: mvn test
18. What is the Maven command to make a JAR File?
Answer: mvn package.
19. How does Maven know to make JAR file when you do ‘mvn package’ command?
Answer: from the packaging element in pom.xml file.
20. What is the default location for your local repository?
Answer: ~/m2./repository
21. What is the command to install JAR file in local repository?
Answer: mvn install
22. What is the command to quickly build your Maven site?
Answer: mvn site
23. What would ‘mvn clean’ do ?
Answer: it will remove the target directory with all the build data before starting so that it is fresh.
24. What would the ‘jar:jar’ goal do?
Answer: jar:jar will not recompile sources – it wills imply just create a JAR from the target/classes directory, under the assumption everything else had already been done.
25. How do you use plugin?
Answer: Add <plugin> element to pom.xml file.
STANDARD Directory layout
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project's license
NOTICE.txt Notices and attributions required by libraries that the project depends on
README.txt Project's readme
26. How can you override directory structure?
Answer: via the project descriptor.
27. How can you add resources to your JAR file?
Answer: place the resource (directory or files) under ${basedir}/src/main/resources
The simple rule applied by Maven is this: any directories or files place within the ${basedir}/src/main/resources directory are packaged in the JAR with the exact same structure starting at the base of the JAR.
28. How you add resources to the classpath for your unit tests?
Answer: To add resources to the classpath for your unit tests, you follow the same pattern as you do for adding resources to the JAR except the directory you place resources in is ${basedir}/src/test/resources.
29. How can you have Maven filter resources when copying?
Answer set filtering to true for the resource directory in your pom.xml file.
30. What is the default value of filtering element in pom.xml file?
Answer: false.
31. How do you reference a property defined in your pom.xml file?
Answer: To reference a property defined in your pom.xml, the property name uses the names of the XML element that define the value, with “pom” being allowed as an alias for the project(root) element. So ${pom.name} refers to the name of the project, ${pom.version} refers to the version of the project, ${pom.build.finalName} refers to the final name of the file created when the built project is packaged, etc. The default values don’t need to be explicitly defined to be available via referencing.
Similarly, values in the user’s settings.xml can be referenced using property names beginning with “setting”.
32. What does ‘mvn process-resources’ command do?
Answer: it copies and filter resources and replace reference with actual value in properties file under resources directory.
33. How to reference a property defined in an external file?
Answer: add a reference of that file in pom.xml and use 31.
34. What is the other alternative of using an external file?
Answer: include the properties in your pom.xml under properties tag. Another alternative is to get values from system properties; either the system properties built into Java ( like java.version or user.home) or poerties defined on the command line using the standard Java –D parameter.
mvn process-resources "-Dcommand.line.prop=hello again"
35. How do you specify dependency?
Answer; using the dependency tag in pom.xml
36. What are the things you need to define for each external dependency?
Answer: groupID, artifactID,version, and scope (compile, test, runtime)
37. Where does Maven reference dependency from?
Answer: Maven looks in your local repository (~/m2/repository).
38. How to search for a dependency (e.g. log4j)/
Answer: search for “site:www.ibiblio.org maven2 log4j” in google.
39. Run the command that will in a multi-module scenario where it will traverse into all the subprojects and run clean, then install.
Answer: mvn clean install
40. What is a goal in building Maven?
Answer: A goal represents a specific task ( finer than a build phase ) which contributes to the building and managing a project. It regulates how a build phase would carry out his duty.
41. What would this command do “ mvn clean dependency:copy-dependencies package”
Answer: The clean phase will be executed first ( meaning it will run all preceeding phases of the clean lifecycle, plus the clean phase itself), and then the dependency:copy_dependencies goal, before finally executing the package phase ( and all its proceeding build phases of the default lifecycle).
42. What are the default values for packaing element? If there is no packaing element defined? What is the default value for that?
Answer: jar, war, ear, pom. JAR.
43. What is the value for packaging element in pom for a project that is purely meta-data?
Answer: pom.
44. What must be done when adding plugins to make it usable?
Answer: Add goals and specify the build phases the goals will be applied.
45. What is the use of execution element in pom file ?
Answer: The execution element is there so that you can run the same goal multiple times with different configuration if needed. Separate execution can also be given an ID so that during inheritance or the application of profiles you can control whether goal configuration is merged or turned into an additional execution.
46. What are the minimum required elements for POM?
Answer: project root, modelVersion, groupID, artifactID, version.
47. What is a project’s fully qualified artifact name?
Answer: <groupId>:<artifactId>:<version>
48. If you do not define any information, where does your pom inherits that information from?
Answer: Super POM.
49. What are the elements in the POM that are merged?
Answer: dependencies,
developers and contributors,
plugin lists ( including reports),
plugin executions with matching ids,
plugin configuration,
resources.
50. how do you override the value of a parent POM ?
Answer: do not include the element in child POM.
51. By Default parent pom.xml is one directory higher than that of the module’s pom.xml . what if the parent is not yet installed and if the directory structure is different?
Answer: we would have to add < relativePath> element to your parent section.
52. What is project Agreegation?
Answer: Project Aggregation is similar to Project Inheritance. But instead of specifying the parent POM from the module, it specifies the modules from the parent POM. By doing so, the parent project now knows its modules, and if a maven command is invoked against the parent project, that maven command will then be executed to the parent’s modules as well.
53. How can you do project aggregation?
Answer: Change the parent POMs packaging to the value “pm” and specify in the parent POM the directories of its modules (child poms).
54. During project aggregation, how do you handle different directory structure?
Answer: <module> ../my-module </module>
55. How can you achieve both Project Aggregation and Project Inheritance?
Answer: Specify in every child POM who their parent POM is.
Change the parent POMs packaging to POM.
Specify in the parent POM the directories of its modules (children POM).
56. How maven processes variables?
Answer: variables are preceded after inheritance as outlined above. This means that if a parent project uses a variable, then its definition in the child, not the parent, will be the one eventually used.
57. How can you customize the build timestamp fromat?
Answer: by declaring the in proerpty element the maven.build.timestamp.format element.
58. How profiles are specified in Maven?
Answer: Profiles are specified using a subset of the elements available in the POM itself.
59. What are the different types of profile in Maven?
Answer: per project, per user, global, profile descriptor.
60. What is the option to specify a profile to be invoked?
Answer: Profiles can be explicitly using the –P CLI option.
mvn groupId:artifactId:goal –P profile-1,profile-2
No profile other than those specified in the option argument will be activated.
61. How can you activate a profile using Maven settings.
Answer: profiles can be activated in the maven settings via the <activeProfile> elements, each containing a profile-id inside.
62. How do you activate a profile when the system property “environment” is specified with value “prod”?
Answer: mvn groupId:artifactId:goal –Denvironment=test
63. How can you activate a profile when a file is missing or existing?
Answer: using the <missing> or <exists> tag in under /profiles/profile/activation xpath.
64. Can you interpolate properties and values defined in POM itself in settings.xml/profile.xml?
Answer: No.
65. What special about using <activeByDefault> element?
Answer: The profile will automatically be active for all builds unless another profile in the same POM is activated using settings.xml/profiles.xml All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config.
66. How to deactivate a profile?
Answer: using the command line by prefixing their identifier with either the character ‘!’ or ‘-‘ as shown below.
mvn groupId:artifactId:goal -P !profile-1,!profile-2
67. What are the elements in POM that a profile can modify when specified in the POM?
Answer: <repositories>, <pluginRepositories>,<dependencies>,<plugins>,<properties>,<modules>
<reporting>,<dependencyManagement>,<distributionManagement>.
68. Why profile is used in Maven?
Answer: to give portability to projects ( e.g. windows, linux etc).
69. What is the use of repositories in Maven?
Answer: A repository in Maven is used to hold build artifacts and dependencies of varying types. There are two type of repositories: local and remote.
70. What are the benefit of storing JARS/external dependencies in local repository instead of remote one?
Answer: It uses less sorage, it makes checking out project quicker, non need for versioning JAR files.
71. How can you download artifacts from a remote repository?
Answer: Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository. By default, Maven will download from the central repository (http://repo1.maven.org/maven2/). To override this, you need to specify a mirror in settings.xml or pom.xml
72. How can you build your project offline?
Answer: mvn –o package.
73. What is transitive dependency in Maven?
Answer: Transitive dependency means to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.
74. How Maven handles and determines what version of dependency will be used when multiple version of an artifact are encountered?
Answer: Maven 2.0 supports only using the “nearest definition” which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it in POM. If two dependency version are at the same depth in the dependency tree, in Maven 2.0.9 it is the order in the declaration that counts. This is called dependency mediation.
75. How do you exclude dependency?
Answer: using the exclusion element.
76. Name all the dependency scope.
Answer: compile (default), provided, runtime, test, system, import.
77. What does dependency management mean in the context of transitive dependency?
Answer: Dependency management mean to allow project authors to directly specify the versions of artifacts to be used when they are encountered in transitive dependencies or in dependencies where no version has been specified. A project can include a dependency in its dependencyManagement section and directly control which version is used.
78. What does import scope means in the context of dependency scope?
Answer: This scope is only used on a dependency of type pom in the <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of dependency.
79. What is the minimal set of information for matching a dependency references against a dependencyManagement section ?
Answer: {groupId,artifactId,type,classifier}.
80. What is a BOM “bill of materials”?
Answer: The root of the project is the BOM pom. It defines the version so f all the artifacts that will be created in the library. Other projects that wish to use the library should import this pom into the dependencyManagement section of their pom. It is basically the parent of the parent.
81. Does Maven handle circularity ( circular reference) in terms of declaring a pom as a parent?
Answer: No
82. What is a system dependency?
Answer: Dependency with scope system are always available and are not looked up in repository, they are usually used to tell Maven about dependencies which are provided by the JDK or the VM. Thus, system dependencies are especially useful for resolving dependencies on artifacts which are now provided by the JDK.
83. What is the use of optional dependency?
Answer: Optional dependencies are used when it is not really possible to split a project up into sub-modules. The idea is that some of the dependencies are only used for certain features in the project, and will not be needed if that feature isn’t used. It is not only important to declare optional dependencies in order to save space/memory/etc. it is vital to control the list of actual dependencies a person needs in order to use aproject.
84. How do you use optional tag?
Answer: setting <optional> true in your dependency declaration.
85. What is the difference between optional dependency and dependency exclusion?
Answer: improvise
86. What does maven-clean-plugin do?
Answer: it is responsible for removing the target directory of Maven 2 project. The clean plugin is used when you want to remove the files generated at build-time in a project’s directory.
87. How can you run the clean plugin automatically during the build?
Answer: you can put the clean plugin inside the execution tag in pom.xml file.
88. Can you delete files other than that in target directory using clean plugin?
Answer: Yes. Using pom.xml file.
89. What is the minimal required information for a plugin to be configured?
Answer: groupId, artifactId, version.
90. Where can you configure your plugins?
Answer: in the configuration section in pom.xml
91. ******How do you see all the parameters for a given goal?*****
Answer: Recent Maven plugins have generally an help goal to have in the command line the description of the plugin, with their parameters and types. To understand the javadoc goal, call:
Mvn javadoc:help –Ddetail –Dgoal=javadoc.
92. How can you bind a mojo to a phase/goal?
Answer: using the @goal,@phase annotation. It can be overridden by phase tag in pom.xml file under plugin configuration.
93. How to stop the propagation of plugins to child POMs?
Answer: set <inherited> to false.
94. If your plugin has a dependency and you want to use the latest version of that artifact, how can you avail this?
Answer: using the dependency tag inside plugin.
95. What can be used to exclude all reports?
Answer: <reportSets>
<reportSet>
<reports/>
</reportSet>
</reportSets>
96. What is the convention for making plugin prefix?
Answer: maven-$prefix-plug for plugins from the apache maven project.
$prefix-maven-plugin for plugins from other sources.
97. When Maven determines plugin information?
Answer: during build time.
98. Why is it illegal to specify a mojo using its plugin-prefix when dealing with lifecycle mappings?
Answer: this helps Maven avoid the case where the ‘jar’ lifecycle behaves differently on two user’s machines, simply due to their local Maven configuration.
99. How do Maven resolves plugin’s version?
Answer: Project’s POM, plugin registry, latest version metadata, release version metadata.
100.What is the packaging type of archtype?
Answer: JAR.
101. What is the command to install 3rd party JARs in local repository?
Answer: mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
102. Which plugin you would use in Maven to call your class?
Answer: exec:java
Is there a way to use the current date in the POM?
Take a look at the buildnumber plugin. It can be used to generate a build date each time I do a build, as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-buildnumber-plugin</artifactId>
<version>0.9.4</version>
<configuration>
<format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
<items>
<item>timestamp</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
pom.xml or settings.xml? What is the best practice configuration usage for these files?
The best practice guideline between settings.xml and pom.xml is that configurations in settings.xml must be specific to the current user and that pom.xml configurations are specific to the project.
For example, <repositories> in pom.xml would tell all users of the project to use the <repositories> specified in the pom.xml. However, some users may prefer to use a mirror instead, so they'll put <mirrors> in their settings.xml so they can choose a faster repository server.
so there you go:
settings.xml -> user scope
pom.xml -> project scope
How do I indicate array types in a MOJO configuration?
<tags>
<tag>value1</tag>
<tag>value2</tag>
</tags>
How should I point a path for maven 2 to use a certain version of JDK when I have different versions of JDK installed on my PC and my JAVA_HOME already set?
If you don't want to change your system JAVA_HOME, set it in maven script instead.
How do I setup the classpath of my antrun plugin to use the classpath from maven?
The maven classpaths are available as ant references when running your ant script. The ant reference names and some examples can be found here: maven-antrun-plugin
Is it possible to use HashMap as configurable parameter in a plugin? How do I configure that in pom.xml?
Yes. Its possible to use a HashMap field as a parameter in your plugin. To use it, your pom configuration should look like this:
<myMap>
<yourkey>yourvalue</yourkey>
.....
</myMap>
How do I filter which classes should be put inside the packaged jar?
All compiled classes are always put into the packaged jar. However, you can configure the compiler plugin to exclude compiling some of the java sources using the compiler parameter excludes as follows:
<project>
...
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/NotNeeded*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
...
</build>
</project>
How can I change the default location of the generated jar when I command "mvn package"?
By default, the location of the generated jar is in ${project.build.directory} or in your target directory.
We can change this by configuring the outputDirectory of maven-jar-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/<!-- directory --></outputDirectory>
</configuration>
</plugin>
How does maven 2 implement reproducibility?
They were removed because they aren't reliable in a transitive environment. It implies that the dependency knows something about the
environment of the dependee, which is back to front. In most cases, granted, the value for war bundle will be the same for a particular
dependency - but that relies on the dependency specifying it.
In the end, we give control to the actual POM doing the building, trying to use sensible defaults that minimise what needs to be
specified, and allowing the use of artifact filters in the configuration of plugins.
What does aggregator mean in mojo?
When a Mojo has a @aggregator expression, it means that It can only build the parent project of your multi-module-project, the one who has the packaging of pom. It can also give you values for the expression ${reactorProjects} where reactorProjects are the MavenProject references to the parent pom modules.
Where is the plugin-registry.xml?
From the settings.xml, you may enable it by setting <usePluginRegistry/> to true
and the file will be in ~/.m2/plugin-registry.xml
How do I create a command line parameter (i.e., -Dname=value ) in my mojo?
In your mojo, put "expression=${<exp>}" in your parameter field
/**
* @parameter expression="${expression.name}"
*/
private String exp;
You may now able to pass parameter values to the command line.
"mvn -Dexpression.name=value install"
How do I convert my <reports> from Maven 1 to Maven 2?
In m1, we declare reports in the pom like this:
<project>
...
<reports>
<report>maven-checkstyle-plugin</report>
<report>maven-pmd-plugin</report>
</reports>
</project>
In m2, the <reports> tag is replaced with <reporting>
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<!-- put your config here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<!-- put your config here -->
</configuration>
</plugin>
</plugins>
<reporting>
</project>
What does the "You cannot have two plugin executions with the same (or missing) elements" message mean?
It means that you have executed a plugin multiple times with the same <id>. Provide each <execution> with a unique <id> then it would be ok.
How do I add my generated sources to the compile path of Maven, when using modello?
Modello generate the sources in the generate-sources phase and automatically adds the source directory for compilation in maven. So you don't have to copy the generated sources. You have to declare the modello-plugin in the build of your plugin for source generation (in that way the sources are generated each time).
What is Maven's order of inheritance?
How do I execute the assembly plugin with different configurations?
Add this to your pom,
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptor>src/main/descriptors/bin.xml</descriptor>
<finalName>${project.build.finalName}-bin</finalName>
</configuration>
</execution>
<execution>
<id>2</id>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptor>src/main/descriptors/src.xml</descriptor>
<finalName>${project.build.finalName}-src</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
and run mvn install, this will execute the assembly plugin twice with different config.
How do I configure the equivalent of maven.war.src of war plugin in Maven 2.0?
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory><!-- put the path of the directory --></warSourceDirectory>
</configuration>
</plugin>
</plugins>
...
</build>
How do I add main class in a generated jar's manifest?
Configure the maven-jar-plugin and add your main class.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
What does the FATAL ERROR with the message "Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log" when using the maven-checkstyle-plugin mean?
Checkstyle uses commons-logging, which has classloader problems when initialized within a Maven plugin's container. This results in the above message - if you run with '-e', you'll see something like the following:
--
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log
--
buried deep in the stacktrace.
The only workaround we currently have for this problem is to include another commons-logging Log implementation in the plugin itself. So, you can solve the problem by adding the following to your plugin declaration in your POM:
<project>
...
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
<reporting>
...
<plugins>
<!-- your checkstyle report is registered here, according to Maven documentation -->
</plugins>
</reporting>
</project>
While this may seem a counter-intuitive way of configuring a report, it's important to remember that Maven plugins can have a mix of reports and normal mojos. When a POM has to configure extra dependencies for a plugin, it should do so in the normal plugins section.
We will probably try to fix this problem before the next release of the checkstyle plugin.
UPDATE: This problem has been fixed in the SVN trunk version of the checkstyle plugin, which should be released very soon. Plugins and Lifecycle, Sites & Reporting, Errors
How do I determine the stale resources in a Mojo to avoid reprocessing them?
This can be done using the following piece of code:
// Imports needed
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
// At some point of your code
StaleSourceScanner scanner = new StaleSourceScanner( 0, Collections.singleton( "**/*.xml" ), Collections.EMPTY_SET );
scanner.addSourceMapping( new SuffixMapping( ".xml", ".html" ) );
Set<File> staleFiles = (Set<File>) scanner.getIncludedSources( this.sourceDirectory, this.targetDirectory );
The second parameter to the StaleSourceScanner is the set of includes, while the third parameter is the set of excludes. You must add a source mapping to the scanner (second line). In this case we're telling the scanner what is the extension of the result file (.html) for each source file extension (.xml). Finally we get the stale files as a Set<File> calling the getIncludedSources method, passing as parameters the source and target directories (of type File). The Maven API doesn't support generics, but you may cast it that way if you're using them.
In order to use this API you must include the following dependency in your pom:
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
Is there a property file for plug-in configuration in Maven 2.0?
No. Maven 2.x no longer supports plug-in configuration via properties files. Instead, in Maven 2.0 you can configure plug-ins directly from command line using the -D arguement, or from the plug-in's POM using the <configuration> element.
How do I determine which POM contains missing transitive dependency?
run "mvn -X"
How do I integrate static (x) html into my Maven site?
You can integrate your static pages in this several steps,
<bannerLeft>
<name>Maven War Plugin</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" xhref="http://maven.apache.org/maven2/"/>
</links>
<menu name="Overview">
<item name="Introduction" xhref="/introduction.html"/>
<item name="How to Use" xhref="/howto.html"/>
</menu>
${reports}
</body>
</project>
Link the static pages by modifying the <menu> section, create items and map it with the filename of the static pages.
<menu name="Overview">
<item name="Introduction" xhref="/introduction.html"/>
<item name="How to Use" xhref="/howto.html"/>
<item name="<put-name-here>" xhref="/<filename-of-the-static-page>"/>
</menu>
How do I run an ant task twice, against two different phases?
You can specify multiple execution elements under the executions tag, giving each a different id and binding them at different phases.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
* <id>one</id>*
<phase>generate-sources</phase>
<configuration>
<tasks>
<echo message="generate-sources!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
*<id>two</id>*
<phase>package</phase>
<configuration>
<tasks>
* <echo message="package!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/>*
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Can a profile inherit the configuration of a "sibling" profile?
No. Profiles merge when their ID's match - so you can inherit them from a parent POM (but you can't inherit profiles from the same POM).
Inheritence and Interpolation, Plugins and Lifecycle, POM
How do I invoke the "maven dist" function from Maven 1.0, in Maven 2.0?
mvn assembly:assembly
See the Assembly Plugin documentation for more details.
General, Plugins and Lifecycle
How do I specify which output folders the Eclipse plugin puts into the .classpath file?
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>target-eclipse</outputDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
...
</build>
What is a Mojo?
A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.
How to produce execution debug output or error messages?
You could call Maven with -X parameter or -e parameter. For more information, run:
mvn --help
Maven compiles my test classes but doesn't run them?
Tests are run by the surefire plugin. The surefire plugin can be configured to run certain test classes and you may have unintentionally done so by specifying a value to ${test}. Check your settings.xml and pom.xml for a property named "test" which would like this:
...
<properties>
<property>
<name>test</name>
<value>some-value</value>
</property>
</properties>
...
Or
...
<properties>
<test>some-value</test>
</properties>
...
How do I include tools.jar in my dependencies?
The following code includes tools.jar on Sun JDKs (it is already included in the runtime for Mac OS X and some free JDKs).
...
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
...
I have a jar that I want to put into my local repository. How can I copy it in?
If you understand the layout of the maven repository, you can copy the jar directly into where it is meant to go. Maven will find this file next time it is run.
If you are not confident about the layout of the maven repository, then you can adapt the following command to load in your jar file, all on one line.
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
This should load in the file into the maven repository, renaming it as needed.
How do I set up Maven so it will compile with a target and source JVM of my choice?
You must configure the source and target parameters in your pom. For example, to set the source and target JVM to 1.5, you should have in your pom :
...
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
...
</build>
...
How can I use Ant tasks in Maven 2?There are currently 2 alternatives:
Why Maven with Eclipse
Eclipse is an industry leader in IDE market, it is used very extensively in developing projects all around the world. Similarly, Maven is a high-level, intelligent project management, build and deployment tool provided by Apache’s software foundation group. Maven deals with application development lifecycle management.
Maven–Eclipse Integration makes the development, testing, packaging and deployment process easy and fast. Maven Integration for Eclipse provides a tight integration for Maven into the IDE and avails the following features:
· It helps to launch Maven builds from within Eclipse
· It avails the dependency management for Eclipse build path based on Maven's pom.xml
· It resolves Maven dependencies from the Eclipse workspace withoutinstalling to local Maven repository
· It avails an automatic downloading of the required dependencies from the remote Maven repositories
· It provides wizards for creating new Maven projects, pom.xml or to enable Maven support on plain Java project
· It helps to search quickly for dependencies in Maven remote repositories
· It quickly fixes in the Java editor for looking up required dependencies/jars by the class or package name.
What do you Need?
1. Get the Eclipse Development Environment :
In this tutorial we are using the eclipse-SDK-3.3-win32, which can be downloaded fromhttp://www.eclipse.org/downloads/
2. Get Maven-eclipse-plugin-plugin :
It is available at http://mevenide.codehaus.org/maven-eclipse-plugin-plugin/
Download and Install Eclipse
First download and install the eclipse plugin on your development machine then proceed with the installation process of the eclipse-maven plugin.
A Maven 2.0 Repository: An IntroductionMaven repository Types:
Use cases for maven repository:
Ant Vs Maven
There is nothing that Maven does that Ant cannot do. Ant gives the ultimate power and flexibility in build and deployment to the developer. But Maven adds a layer of abstraction above Ant (and uses Jelly). Maven can be used to build any Java application. Today JEE build and deployment has become much standardized. Every enterprise has some variations, but in general it is all the same: deploying EARs, WARs, and EJB-JARs. Maven captures this intelligence and lets you achieve the build and deployment in about 5-6 lines of Maven script compared to dozens of lines in an Ant build script.
Ant lets you do any variations you want, but requires a lot of scripting. Maven on the other hand mandates certain directories and file names, but it provides plugins to make life easier. The restriction imposed by Maven is that only one artifact is generated per project (A project in Maven terminology is a folder with a project.xml file in it). A Maven project can have sub projects. Each sub project can build its own artifact. The topmost project can aggregate the artifacts into a larger one. This is synonymous to jars and wars put together to form an EAR. Maven also provides inheritance in projects.
Maven : Stealing the show
Maven simplifies build enormously by imposing certain fixed file names and acceptable restrictions like one artifact per project. Artifacts are treated as files on your computer by the build script. Maven hides the fact that everything is a file and forces you to think and script to create a deployable artifact such as an EAR. Artifact has a dependency on a particular version of a third party library residing in a shared remote (or local) enterprise repository, and then publish your library into the repository as well for others to use. Hence there are no more classpath issues. No more mismatch in libraries. It also gives the power to embed even the Ant scripts within Maven scripts if absolutely essential.
Maven 2.0: FeaturesMaven is a high-level, intelligent project management, build and deployment tool provided by Apache's software foundation group. Maven deals with application development lifecycle management. Maven was originally developed to manage and to minimize the complexities of building the Jakarta Turbine project. But its powerful capabilities have made it a core entity of the Apache Software Foundation projects. Actually, for a long time there was a need to standardized project development lifecycle management system and Maven has emerged as a perfect option that meets the needs. Maven has become the de- facto build system in many open source initiatives and it is rapidly being adopted by many software development organizations.
Maven was borne of the very practical desire to make several projects at Apache work in a consistence manner. So that developers could freely move between these projects, knowing clearly how they all worked by understanding how one of them worked.
If a developer spent time understanding how one project built it was intended that they would not have to go through this process again when they moved on to the next project. The same idea extends to testing, generating documentation, generating metrics and reports, testing and deploying. All projects share enough of the same characteristics, an understanding of which Maven tries to harness in its general approach to project management.
On a very high level all projects need to be built, tested, packaged, documented and deployed. There occurs infinite variation in each of the above mentioned steps, but these variation still occur within the confines of a well defined path and it is this path that Maven attempts to present to everyone in a clear way. The easiest way to make a path clear is to provide people with a set of patterns that can be shared by anyone involved in a project.
The key benefit of this approach is that developers can follow one consistent build lifecycle management process without having to reinvent such processes again. Ultimately this makes developers more productive, agile, disciplined, and focused on the work at hand rather than spending time and effort doing grunt work understanding, developing, and configuring yet another non-standard build system.
Maven: Features
The primary goal of maven is to allow the developers to comprehend the complete state of a project in the shortest time by using easy build process, uniform building system, quality project management information (such as change Log, cross-reference, mailing lists, dependencies, unit test reports, test coverage reports and many more), guidelines for best practices and transparent migration to new features. To achieve to this goal Maven attempts to deal with several areas like:
Maven 2.0 was first released on 19 October 2005 and it is not backward compatible with the plugins and the projects of maven1. In December 2005, a lot of plugins were added to maven but not all plugins that exists for maven1 are ported yet. Maven 2 is expected to stabilize quickly with most of the Open Source technologies. People are introduced to use maven as the core build system for Java development in one project and a multi-project environment. After a little knowledge about the maven, developers are able to setup a new project with maven and also become aware of the default maven project structure. Developers are easily enabled to configure maven and its plugins for a project. Developers enable common settings for maven and its plugins over multiple projects, how to generate, distribute and deploy products and reports with maven so that they can use repositories to set up a company repository. Developers can also know about the most important plugins about how to install, configure and use them, just to look for other plugins to evaluate them so that they can be integrated in their work environment.
Maven is the standard way to build projects and it also provides various other characters like clearing the definition of the project, ways to share jars across projects. It also provides the easy way to publish project information (OOS).
Originally maven was designed to simplify the building processes in the Jakarta Turbine project. Several projects were there containing their own slightly different Ant build files and JARs were checked into CVS. An apache group's tool that can build the projects, publish project information, defines what the project consists of and that can share JARs across several projects. The result of all these requirement was the maven tool that builds and manages the java-based-project.
Answer: Build, Documentation, Reporting, Dependencies, SCMs, Releases, Distribution.
2. What is a Maven Arch-type?
Answer: An arch-type is defined as an original model or pattern from which all other things of the same kind are made. In Maven, an arch-type is a template of a project which is combined with some user input to get the desired outcome.
3. What is the command to create a new project based on an archtype?
Answer: mvn archetype:generate
4. What makes up an arch-type?
Answer: Archtypes are packaged up in Jar file and they consist of the archtype metadata which describes the content of the archtype and a set of Velocity templates which make up a prototype project.
5. What is POM?
Answer: A Project object Model or POM is the fundamental unit of work in Maven. It is an xml file that contains information about the project and configuration details used to build a project by Maven. It contains default value for most projects. Like, the build directory is ‘target’.
6. Name the build, source and test source directory for POM in Maven.
Answer: build=target, source=src/main/java,test=src/main/test.
7. How do you know the version of mvn you are using?
Answer: mvn --version
8. Name the 3 build lifecycle of Maven
Answer: default, clean and site.
9. Name default phases of a build lifecycle in Maven.
Answer: validate, compile, test, package, integration test, verify, install deploy.
10. What would this command do “mvn clean dependency:copy-dependencies package” ?
Answer: This command will clean the project, copy the dependencies and execute all phases up to and including project.
11. What is Maven?
Answer: Maven is an attempt to apply patterns to a project’s build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool.
12. Can Installation and user configuration be used to add shared project information?
Answer: No. For this, you should have your projects inherit from a company-wide parent pom.xml
13. How many artifacts are downloaded at a time from different groups by default?
Answer: 5. To only download single artifacts at a time, do
mvn –Dmaven.artifact.thread=1 clean install
To set this option permanently use MAVEN_OPTS environment variable to -Dmaven.artifact.threads=3
14. How do you compile your source code in Maven?
Answer: Change to the directory where pom.xml is created by archetype:create and execute the following command to compile your application sources.
mvn compile
15. When you compile a Maven project, where do you find the class files?
Answer: ${basedir}/target/classes/
16. What command should you use if you simply want to compile your test sources ( but not execute the tests?
Answer: mvn test-compile
17. How do you compile my test sources and run my unit tests?
Answer: mvn test
18. What is the Maven command to make a JAR File?
Answer: mvn package.
19. How does Maven know to make JAR file when you do ‘mvn package’ command?
Answer: from the packaging element in pom.xml file.
20. What is the default location for your local repository?
Answer: ~/m2./repository
21. What is the command to install JAR file in local repository?
Answer: mvn install
22. What is the command to quickly build your Maven site?
Answer: mvn site
23. What would ‘mvn clean’ do ?
Answer: it will remove the target directory with all the build data before starting so that it is fresh.
24. What would the ‘jar:jar’ goal do?
Answer: jar:jar will not recompile sources – it wills imply just create a JAR from the target/classes directory, under the assumption everything else had already been done.
25. How do you use plugin?
Answer: Add <plugin> element to pom.xml file.
STANDARD Directory layout
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project's license
NOTICE.txt Notices and attributions required by libraries that the project depends on
README.txt Project's readme
26. How can you override directory structure?
Answer: via the project descriptor.
27. How can you add resources to your JAR file?
Answer: place the resource (directory or files) under ${basedir}/src/main/resources
The simple rule applied by Maven is this: any directories or files place within the ${basedir}/src/main/resources directory are packaged in the JAR with the exact same structure starting at the base of the JAR.
28. How you add resources to the classpath for your unit tests?
Answer: To add resources to the classpath for your unit tests, you follow the same pattern as you do for adding resources to the JAR except the directory you place resources in is ${basedir}/src/test/resources.
29. How can you have Maven filter resources when copying?
Answer set filtering to true for the resource directory in your pom.xml file.
30. What is the default value of filtering element in pom.xml file?
Answer: false.
31. How do you reference a property defined in your pom.xml file?
Answer: To reference a property defined in your pom.xml, the property name uses the names of the XML element that define the value, with “pom” being allowed as an alias for the project(root) element. So ${pom.name} refers to the name of the project, ${pom.version} refers to the version of the project, ${pom.build.finalName} refers to the final name of the file created when the built project is packaged, etc. The default values don’t need to be explicitly defined to be available via referencing.
Similarly, values in the user’s settings.xml can be referenced using property names beginning with “setting”.
32. What does ‘mvn process-resources’ command do?
Answer: it copies and filter resources and replace reference with actual value in properties file under resources directory.
33. How to reference a property defined in an external file?
Answer: add a reference of that file in pom.xml and use 31.
34. What is the other alternative of using an external file?
Answer: include the properties in your pom.xml under properties tag. Another alternative is to get values from system properties; either the system properties built into Java ( like java.version or user.home) or poerties defined on the command line using the standard Java –D parameter.
mvn process-resources "-Dcommand.line.prop=hello again"
35. How do you specify dependency?
Answer; using the dependency tag in pom.xml
36. What are the things you need to define for each external dependency?
Answer: groupID, artifactID,version, and scope (compile, test, runtime)
37. Where does Maven reference dependency from?
Answer: Maven looks in your local repository (~/m2/repository).
38. How to search for a dependency (e.g. log4j)/
Answer: search for “site:www.ibiblio.org maven2 log4j” in google.
39. Run the command that will in a multi-module scenario where it will traverse into all the subprojects and run clean, then install.
Answer: mvn clean install
40. What is a goal in building Maven?
Answer: A goal represents a specific task ( finer than a build phase ) which contributes to the building and managing a project. It regulates how a build phase would carry out his duty.
41. What would this command do “ mvn clean dependency:copy-dependencies package”
Answer: The clean phase will be executed first ( meaning it will run all preceeding phases of the clean lifecycle, plus the clean phase itself), and then the dependency:copy_dependencies goal, before finally executing the package phase ( and all its proceeding build phases of the default lifecycle).
42. What are the default values for packaing element? If there is no packaing element defined? What is the default value for that?
Answer: jar, war, ear, pom. JAR.
43. What is the value for packaging element in pom for a project that is purely meta-data?
Answer: pom.
44. What must be done when adding plugins to make it usable?
Answer: Add goals and specify the build phases the goals will be applied.
45. What is the use of execution element in pom file ?
Answer: The execution element is there so that you can run the same goal multiple times with different configuration if needed. Separate execution can also be given an ID so that during inheritance or the application of profiles you can control whether goal configuration is merged or turned into an additional execution.
46. What are the minimum required elements for POM?
Answer: project root, modelVersion, groupID, artifactID, version.
47. What is a project’s fully qualified artifact name?
Answer: <groupId>:<artifactId>:<version>
48. If you do not define any information, where does your pom inherits that information from?
Answer: Super POM.
49. What are the elements in the POM that are merged?
Answer: dependencies,
developers and contributors,
plugin lists ( including reports),
plugin executions with matching ids,
plugin configuration,
resources.
50. how do you override the value of a parent POM ?
Answer: do not include the element in child POM.
51. By Default parent pom.xml is one directory higher than that of the module’s pom.xml . what if the parent is not yet installed and if the directory structure is different?
Answer: we would have to add < relativePath> element to your parent section.
52. What is project Agreegation?
Answer: Project Aggregation is similar to Project Inheritance. But instead of specifying the parent POM from the module, it specifies the modules from the parent POM. By doing so, the parent project now knows its modules, and if a maven command is invoked against the parent project, that maven command will then be executed to the parent’s modules as well.
53. How can you do project aggregation?
Answer: Change the parent POMs packaging to the value “pm” and specify in the parent POM the directories of its modules (child poms).
54. During project aggregation, how do you handle different directory structure?
Answer: <module> ../my-module </module>
55. How can you achieve both Project Aggregation and Project Inheritance?
Answer: Specify in every child POM who their parent POM is.
Change the parent POMs packaging to POM.
Specify in the parent POM the directories of its modules (children POM).
56. How maven processes variables?
Answer: variables are preceded after inheritance as outlined above. This means that if a parent project uses a variable, then its definition in the child, not the parent, will be the one eventually used.
57. How can you customize the build timestamp fromat?
Answer: by declaring the in proerpty element the maven.build.timestamp.format element.
58. How profiles are specified in Maven?
Answer: Profiles are specified using a subset of the elements available in the POM itself.
59. What are the different types of profile in Maven?
Answer: per project, per user, global, profile descriptor.
60. What is the option to specify a profile to be invoked?
Answer: Profiles can be explicitly using the –P CLI option.
mvn groupId:artifactId:goal –P profile-1,profile-2
No profile other than those specified in the option argument will be activated.
61. How can you activate a profile using Maven settings.
Answer: profiles can be activated in the maven settings via the <activeProfile> elements, each containing a profile-id inside.
62. How do you activate a profile when the system property “environment” is specified with value “prod”?
Answer: mvn groupId:artifactId:goal –Denvironment=test
63. How can you activate a profile when a file is missing or existing?
Answer: using the <missing> or <exists> tag in under /profiles/profile/activation xpath.
64. Can you interpolate properties and values defined in POM itself in settings.xml/profile.xml?
Answer: No.
65. What special about using <activeByDefault> element?
Answer: The profile will automatically be active for all builds unless another profile in the same POM is activated using settings.xml/profiles.xml All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config.
66. How to deactivate a profile?
Answer: using the command line by prefixing their identifier with either the character ‘!’ or ‘-‘ as shown below.
mvn groupId:artifactId:goal -P !profile-1,!profile-2
67. What are the elements in POM that a profile can modify when specified in the POM?
Answer: <repositories>, <pluginRepositories>,<dependencies>,<plugins>,<properties>,<modules>
<reporting>,<dependencyManagement>,<distributionManagement>.
68. Why profile is used in Maven?
Answer: to give portability to projects ( e.g. windows, linux etc).
69. What is the use of repositories in Maven?
Answer: A repository in Maven is used to hold build artifacts and dependencies of varying types. There are two type of repositories: local and remote.
70. What are the benefit of storing JARS/external dependencies in local repository instead of remote one?
Answer: It uses less sorage, it makes checking out project quicker, non need for versioning JAR files.
71. How can you download artifacts from a remote repository?
Answer: Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository. By default, Maven will download from the central repository (http://repo1.maven.org/maven2/). To override this, you need to specify a mirror in settings.xml or pom.xml
72. How can you build your project offline?
Answer: mvn –o package.
73. What is transitive dependency in Maven?
Answer: Transitive dependency means to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.
74. How Maven handles and determines what version of dependency will be used when multiple version of an artifact are encountered?
Answer: Maven 2.0 supports only using the “nearest definition” which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it in POM. If two dependency version are at the same depth in the dependency tree, in Maven 2.0.9 it is the order in the declaration that counts. This is called dependency mediation.
75. How do you exclude dependency?
Answer: using the exclusion element.
76. Name all the dependency scope.
Answer: compile (default), provided, runtime, test, system, import.
77. What does dependency management mean in the context of transitive dependency?
Answer: Dependency management mean to allow project authors to directly specify the versions of artifacts to be used when they are encountered in transitive dependencies or in dependencies where no version has been specified. A project can include a dependency in its dependencyManagement section and directly control which version is used.
78. What does import scope means in the context of dependency scope?
Answer: This scope is only used on a dependency of type pom in the <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of dependency.
79. What is the minimal set of information for matching a dependency references against a dependencyManagement section ?
Answer: {groupId,artifactId,type,classifier}.
80. What is a BOM “bill of materials”?
Answer: The root of the project is the BOM pom. It defines the version so f all the artifacts that will be created in the library. Other projects that wish to use the library should import this pom into the dependencyManagement section of their pom. It is basically the parent of the parent.
81. Does Maven handle circularity ( circular reference) in terms of declaring a pom as a parent?
Answer: No
82. What is a system dependency?
Answer: Dependency with scope system are always available and are not looked up in repository, they are usually used to tell Maven about dependencies which are provided by the JDK or the VM. Thus, system dependencies are especially useful for resolving dependencies on artifacts which are now provided by the JDK.
83. What is the use of optional dependency?
Answer: Optional dependencies are used when it is not really possible to split a project up into sub-modules. The idea is that some of the dependencies are only used for certain features in the project, and will not be needed if that feature isn’t used. It is not only important to declare optional dependencies in order to save space/memory/etc. it is vital to control the list of actual dependencies a person needs in order to use aproject.
84. How do you use optional tag?
Answer: setting <optional> true in your dependency declaration.
85. What is the difference between optional dependency and dependency exclusion?
Answer: improvise
86. What does maven-clean-plugin do?
Answer: it is responsible for removing the target directory of Maven 2 project. The clean plugin is used when you want to remove the files generated at build-time in a project’s directory.
87. How can you run the clean plugin automatically during the build?
Answer: you can put the clean plugin inside the execution tag in pom.xml file.
88. Can you delete files other than that in target directory using clean plugin?
Answer: Yes. Using pom.xml file.
89. What is the minimal required information for a plugin to be configured?
Answer: groupId, artifactId, version.
90. Where can you configure your plugins?
Answer: in the configuration section in pom.xml
91. ******How do you see all the parameters for a given goal?*****
Answer: Recent Maven plugins have generally an help goal to have in the command line the description of the plugin, with their parameters and types. To understand the javadoc goal, call:
Mvn javadoc:help –Ddetail –Dgoal=javadoc.
92. How can you bind a mojo to a phase/goal?
Answer: using the @goal,@phase annotation. It can be overridden by phase tag in pom.xml file under plugin configuration.
93. How to stop the propagation of plugins to child POMs?
Answer: set <inherited> to false.
94. If your plugin has a dependency and you want to use the latest version of that artifact, how can you avail this?
Answer: using the dependency tag inside plugin.
95. What can be used to exclude all reports?
Answer: <reportSets>
<reportSet>
<reports/>
</reportSet>
</reportSets>
96. What is the convention for making plugin prefix?
Answer: maven-$prefix-plug for plugins from the apache maven project.
$prefix-maven-plugin for plugins from other sources.
97. When Maven determines plugin information?
Answer: during build time.
98. Why is it illegal to specify a mojo using its plugin-prefix when dealing with lifecycle mappings?
Answer: this helps Maven avoid the case where the ‘jar’ lifecycle behaves differently on two user’s machines, simply due to their local Maven configuration.
99. How do Maven resolves plugin’s version?
Answer: Project’s POM, plugin registry, latest version metadata, release version metadata.
100.What is the packaging type of archtype?
Answer: JAR.
101. What is the command to install 3rd party JARs in local repository?
Answer: mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
102. Which plugin you would use in Maven to call your class?
Answer: exec:java
Is there a way to use the current date in the POM?
Take a look at the buildnumber plugin. It can be used to generate a build date each time I do a build, as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-buildnumber-plugin</artifactId>
<version>0.9.4</version>
<configuration>
<format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
<items>
<item>timestamp</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
pom.xml or settings.xml? What is the best practice configuration usage for these files?
The best practice guideline between settings.xml and pom.xml is that configurations in settings.xml must be specific to the current user and that pom.xml configurations are specific to the project.
For example, <repositories> in pom.xml would tell all users of the project to use the <repositories> specified in the pom.xml. However, some users may prefer to use a mirror instead, so they'll put <mirrors> in their settings.xml so they can choose a faster repository server.
so there you go:
settings.xml -> user scope
pom.xml -> project scope
How do I indicate array types in a MOJO configuration?
<tags>
<tag>value1</tag>
<tag>value2</tag>
</tags>
How should I point a path for maven 2 to use a certain version of JDK when I have different versions of JDK installed on my PC and my JAVA_HOME already set?
If you don't want to change your system JAVA_HOME, set it in maven script instead.
How do I setup the classpath of my antrun plugin to use the classpath from maven?
The maven classpaths are available as ant references when running your ant script. The ant reference names and some examples can be found here: maven-antrun-plugin
Is it possible to use HashMap as configurable parameter in a plugin? How do I configure that in pom.xml?
Yes. Its possible to use a HashMap field as a parameter in your plugin. To use it, your pom configuration should look like this:
<myMap>
<yourkey>yourvalue</yourkey>
.....
</myMap>
How do I filter which classes should be put inside the packaged jar?
All compiled classes are always put into the packaged jar. However, you can configure the compiler plugin to exclude compiling some of the java sources using the compiler parameter excludes as follows:
<project>
...
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/NotNeeded*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
...
</build>
</project>
How can I change the default location of the generated jar when I command "mvn package"?
By default, the location of the generated jar is in ${project.build.directory} or in your target directory.
We can change this by configuring the outputDirectory of maven-jar-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/<!-- directory --></outputDirectory>
</configuration>
</plugin>
How does maven 2 implement reproducibility?
- Add the exact versions of plugins into your pluginDepenencies (make use of the release plugin)
- Make use of ibiblio for your libraries. This should always be the case for jars. (The group is working on stabilising metadata and techniques for locking it down even if it changes. An internal repository mirror that doesn't fetch updates (only new) is recommended for true reproducibility.)
They were removed because they aren't reliable in a transitive environment. It implies that the dependency knows something about the
environment of the dependee, which is back to front. In most cases, granted, the value for war bundle will be the same for a particular
dependency - but that relies on the dependency specifying it.
In the end, we give control to the actual POM doing the building, trying to use sensible defaults that minimise what needs to be
specified, and allowing the use of artifact filters in the configuration of plugins.
What does aggregator mean in mojo?
When a Mojo has a @aggregator expression, it means that It can only build the parent project of your multi-module-project, the one who has the packaging of pom. It can also give you values for the expression ${reactorProjects} where reactorProjects are the MavenProject references to the parent pom modules.
Where is the plugin-registry.xml?
From the settings.xml, you may enable it by setting <usePluginRegistry/> to true
and the file will be in ~/.m2/plugin-registry.xml
How do I create a command line parameter (i.e., -Dname=value ) in my mojo?
In your mojo, put "expression=${<exp>}" in your parameter field
/**
* @parameter expression="${expression.name}"
*/
private String exp;
You may now able to pass parameter values to the command line.
"mvn -Dexpression.name=value install"
How do I convert my <reports> from Maven 1 to Maven 2?
In m1, we declare reports in the pom like this:
<project>
...
<reports>
<report>maven-checkstyle-plugin</report>
<report>maven-pmd-plugin</report>
</reports>
</project>
In m2, the <reports> tag is replaced with <reporting>
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<!-- put your config here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<!-- put your config here -->
</configuration>
</plugin>
</plugins>
<reporting>
</project>
What does the "You cannot have two plugin executions with the same (or missing) elements" message mean?
It means that you have executed a plugin multiple times with the same <id>. Provide each <execution> with a unique <id> then it would be ok.
How do I add my generated sources to the compile path of Maven, when using modello?
Modello generate the sources in the generate-sources phase and automatically adds the source directory for compilation in maven. So you don't have to copy the generated sources. You have to declare the modello-plugin in the build of your plugin for source generation (in that way the sources are generated each time).
What is Maven's order of inheritance?
- parent pom
- project pom
- settings
- CLI parameters
How do I execute the assembly plugin with different configurations?
Add this to your pom,
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptor>src/main/descriptors/bin.xml</descriptor>
<finalName>${project.build.finalName}-bin</finalName>
</configuration>
</execution>
<execution>
<id>2</id>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptor>src/main/descriptors/src.xml</descriptor>
<finalName>${project.build.finalName}-src</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
and run mvn install, this will execute the assembly plugin twice with different config.
How do I configure the equivalent of maven.war.src of war plugin in Maven 2.0?
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory><!-- put the path of the directory --></warSourceDirectory>
</configuration>
</plugin>
</plugins>
...
</build>
How do I add main class in a generated jar's manifest?
Configure the maven-jar-plugin and add your main class.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
What does the FATAL ERROR with the message "Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log" when using the maven-checkstyle-plugin mean?
Checkstyle uses commons-logging, which has classloader problems when initialized within a Maven plugin's container. This results in the above message - if you run with '-e', you'll see something like the following:
--
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log
--
buried deep in the stacktrace.
The only workaround we currently have for this problem is to include another commons-logging Log implementation in the plugin itself. So, you can solve the problem by adding the following to your plugin declaration in your POM:
<project>
...
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
<reporting>
...
<plugins>
<!-- your checkstyle report is registered here, according to Maven documentation -->
</plugins>
</reporting>
</project>
While this may seem a counter-intuitive way of configuring a report, it's important to remember that Maven plugins can have a mix of reports and normal mojos. When a POM has to configure extra dependencies for a plugin, it should do so in the normal plugins section.
We will probably try to fix this problem before the next release of the checkstyle plugin.
UPDATE: This problem has been fixed in the SVN trunk version of the checkstyle plugin, which should be released very soon. Plugins and Lifecycle, Sites & Reporting, Errors
How do I determine the stale resources in a Mojo to avoid reprocessing them?
This can be done using the following piece of code:
// Imports needed
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
// At some point of your code
StaleSourceScanner scanner = new StaleSourceScanner( 0, Collections.singleton( "**/*.xml" ), Collections.EMPTY_SET );
scanner.addSourceMapping( new SuffixMapping( ".xml", ".html" ) );
Set<File> staleFiles = (Set<File>) scanner.getIncludedSources( this.sourceDirectory, this.targetDirectory );
The second parameter to the StaleSourceScanner is the set of includes, while the third parameter is the set of excludes. You must add a source mapping to the scanner (second line). In this case we're telling the scanner what is the extension of the result file (.html) for each source file extension (.xml). Finally we get the stale files as a Set<File> calling the getIncludedSources method, passing as parameters the source and target directories (of type File). The Maven API doesn't support generics, but you may cast it that way if you're using them.
In order to use this API you must include the following dependency in your pom:
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
Is there a property file for plug-in configuration in Maven 2.0?
No. Maven 2.x no longer supports plug-in configuration via properties files. Instead, in Maven 2.0 you can configure plug-ins directly from command line using the -D arguement, or from the plug-in's POM using the <configuration> element.
How do I determine which POM contains missing transitive dependency?
run "mvn -X"
How do I integrate static (x) html into my Maven site?
You can integrate your static pages in this several steps,
- Put your static pages in the resources directory, ${basedir}/src/site/resources.
- Create your site.xml and put it in ${basedir}/src/site. An example below:
<bannerLeft>
<name>Maven War Plugin</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" xhref="http://maven.apache.org/maven2/"/>
</links>
<menu name="Overview">
<item name="Introduction" xhref="/introduction.html"/>
<item name="How to Use" xhref="/howto.html"/>
</menu>
${reports}
</body>
</project>
Link the static pages by modifying the <menu> section, create items and map it with the filename of the static pages.
<menu name="Overview">
<item name="Introduction" xhref="/introduction.html"/>
<item name="How to Use" xhref="/howto.html"/>
<item name="<put-name-here>" xhref="/<filename-of-the-static-page>"/>
</menu>
How do I run an ant task twice, against two different phases?
You can specify multiple execution elements under the executions tag, giving each a different id and binding them at different phases.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
* <id>one</id>*
<phase>generate-sources</phase>
<configuration>
<tasks>
<echo message="generate-sources!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
*<id>two</id>*
<phase>package</phase>
<configuration>
<tasks>
* <echo message="package!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/>*
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Can a profile inherit the configuration of a "sibling" profile?
No. Profiles merge when their ID's match - so you can inherit them from a parent POM (but you can't inherit profiles from the same POM).
Inheritence and Interpolation, Plugins and Lifecycle, POM
How do I invoke the "maven dist" function from Maven 1.0, in Maven 2.0?
mvn assembly:assembly
See the Assembly Plugin documentation for more details.
General, Plugins and Lifecycle
How do I specify which output folders the Eclipse plugin puts into the .classpath file?
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>target-eclipse</outputDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
...
</build>
What is a Mojo?
A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.
How to produce execution debug output or error messages?
You could call Maven with -X parameter or -e parameter. For more information, run:
mvn --help
Maven compiles my test classes but doesn't run them?
Tests are run by the surefire plugin. The surefire plugin can be configured to run certain test classes and you may have unintentionally done so by specifying a value to ${test}. Check your settings.xml and pom.xml for a property named "test" which would like this:
...
<properties>
<property>
<name>test</name>
<value>some-value</value>
</property>
</properties>
...
Or
...
<properties>
<test>some-value</test>
</properties>
...
How do I include tools.jar in my dependencies?
The following code includes tools.jar on Sun JDKs (it is already included in the runtime for Mac OS X and some free JDKs).
...
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
...
I have a jar that I want to put into my local repository. How can I copy it in?
If you understand the layout of the maven repository, you can copy the jar directly into where it is meant to go. Maven will find this file next time it is run.
If you are not confident about the layout of the maven repository, then you can adapt the following command to load in your jar file, all on one line.
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
This should load in the file into the maven repository, renaming it as needed.
How do I set up Maven so it will compile with a target and source JVM of my choice?
You must configure the source and target parameters in your pom. For example, to set the source and target JVM to 1.5, you should have in your pom :
...
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
...
</build>
...
How can I use Ant tasks in Maven 2?There are currently 2 alternatives:
- For use in a plugin written in Java, Beanshell or other Java-like scripting language, you can construct the Ant tasks using the instructions given in the Ant documentation
- If you have very small amounts of Ant script specific to your project, you can use the AntRun plugin.
Why Maven with Eclipse
Eclipse is an industry leader in IDE market, it is used very extensively in developing projects all around the world. Similarly, Maven is a high-level, intelligent project management, build and deployment tool provided by Apache’s software foundation group. Maven deals with application development lifecycle management.
Maven–Eclipse Integration makes the development, testing, packaging and deployment process easy and fast. Maven Integration for Eclipse provides a tight integration for Maven into the IDE and avails the following features:
· It helps to launch Maven builds from within Eclipse
· It avails the dependency management for Eclipse build path based on Maven's pom.xml
· It resolves Maven dependencies from the Eclipse workspace withoutinstalling to local Maven repository
· It avails an automatic downloading of the required dependencies from the remote Maven repositories
· It provides wizards for creating new Maven projects, pom.xml or to enable Maven support on plain Java project
· It helps to search quickly for dependencies in Maven remote repositories
· It quickly fixes in the Java editor for looking up required dependencies/jars by the class or package name.
What do you Need?
1. Get the Eclipse Development Environment :
In this tutorial we are using the eclipse-SDK-3.3-win32, which can be downloaded fromhttp://www.eclipse.org/downloads/
2. Get Maven-eclipse-plugin-plugin :
It is available at http://mevenide.codehaus.org/maven-eclipse-plugin-plugin/
Download and Install Eclipse
First download and install the eclipse plugin on your development machine then proceed with the installation process of the eclipse-maven plugin.
A Maven 2.0 Repository: An IntroductionMaven repository Types:
- Public remote external repository: This public external repository exists at ibiblio.org and maven synchronizes with this repository.
- Private remote internal repository: We set up this repository and make changes in the maven's pom.xml or settings.xml file to use this repository.
- Local repository: This repository is maintained by the developer and stays on the developer's machine. It is synchronous to the maven repository defined in the settings.xml file that exists in the .m2 directory at its standard location i.e. C:\Documents and Settings\Administrator. If no private internal repository is setup and not listed in the pom.xml or in the setting.xml then the local repository exists on the developer's machine is synchronized with the public maven repository at ibiblio.org.
- Reduces conflicts among likelihood versions.
- To build first time it requires less manual intervention.
- Rather than having several separate independent libraries it provides a single central reference repository for all the dependent software libraries.
- It quickly builds the project while using an internal repository as maven artifacts are retrieved from the intranet server rather than retrieving from the server on internet.
Use cases for maven repository:
- It creates two sub-repository inside the internal repository.
- Downloads ibiblio-cache from ibiblio for artifacts and make it available publically. This synchronizes with external repository from ibiblio.
- internal-maven-repository: used for internal artifacts of an organization. It contains unique artifacts for the organization and is not synchronized with any repository.
- Alternatively, another sub-repository that is not at ibiblio can be created for artifacts. This does not synchronize with any external repository.
- Browse the remote repository by using a web browser.
- Search the artifacts in the repository.
- Download code from version control and make changes in settings.xml to point to the internal repository and build without any manual intervention.
- Install new version of the artifacts.
- Import artifacts into the repository in bulk.
- Export artifacts from the repository in bulk.
- Setup the task to backup the repository automatically.
- Free and open source
- Provide admin tools
- Easy to setup and use
- Provide backup facility
- Able to create, edit and delete sub repositories.
- Anonymous read only access and also access control facility.
- Deployable in any standard web server such as Tomcat or Apache.
- Issue tracker, forums and other independent source of information.
- Active community developers make the product enhanced and bugs fixed.
- Bulk import/export facility to move groups of artifacts into the repository and out of the repository.
- Provide a repository browser: should be a web browser instead of the desktop application.
Ant Vs Maven
There is nothing that Maven does that Ant cannot do. Ant gives the ultimate power and flexibility in build and deployment to the developer. But Maven adds a layer of abstraction above Ant (and uses Jelly). Maven can be used to build any Java application. Today JEE build and deployment has become much standardized. Every enterprise has some variations, but in general it is all the same: deploying EARs, WARs, and EJB-JARs. Maven captures this intelligence and lets you achieve the build and deployment in about 5-6 lines of Maven script compared to dozens of lines in an Ant build script.
Ant lets you do any variations you want, but requires a lot of scripting. Maven on the other hand mandates certain directories and file names, but it provides plugins to make life easier. The restriction imposed by Maven is that only one artifact is generated per project (A project in Maven terminology is a folder with a project.xml file in it). A Maven project can have sub projects. Each sub project can build its own artifact. The topmost project can aggregate the artifacts into a larger one. This is synonymous to jars and wars put together to form an EAR. Maven also provides inheritance in projects.
Maven : Stealing the show
Maven simplifies build enormously by imposing certain fixed file names and acceptable restrictions like one artifact per project. Artifacts are treated as files on your computer by the build script. Maven hides the fact that everything is a file and forces you to think and script to create a deployable artifact such as an EAR. Artifact has a dependency on a particular version of a third party library residing in a shared remote (or local) enterprise repository, and then publish your library into the repository as well for others to use. Hence there are no more classpath issues. No more mismatch in libraries. It also gives the power to embed even the Ant scripts within Maven scripts if absolutely essential.
Maven 2.0: FeaturesMaven is a high-level, intelligent project management, build and deployment tool provided by Apache's software foundation group. Maven deals with application development lifecycle management. Maven was originally developed to manage and to minimize the complexities of building the Jakarta Turbine project. But its powerful capabilities have made it a core entity of the Apache Software Foundation projects. Actually, for a long time there was a need to standardized project development lifecycle management system and Maven has emerged as a perfect option that meets the needs. Maven has become the de- facto build system in many open source initiatives and it is rapidly being adopted by many software development organizations.
Maven was borne of the very practical desire to make several projects at Apache work in a consistence manner. So that developers could freely move between these projects, knowing clearly how they all worked by understanding how one of them worked.
If a developer spent time understanding how one project built it was intended that they would not have to go through this process again when they moved on to the next project. The same idea extends to testing, generating documentation, generating metrics and reports, testing and deploying. All projects share enough of the same characteristics, an understanding of which Maven tries to harness in its general approach to project management.
On a very high level all projects need to be built, tested, packaged, documented and deployed. There occurs infinite variation in each of the above mentioned steps, but these variation still occur within the confines of a well defined path and it is this path that Maven attempts to present to everyone in a clear way. The easiest way to make a path clear is to provide people with a set of patterns that can be shared by anyone involved in a project.
The key benefit of this approach is that developers can follow one consistent build lifecycle management process without having to reinvent such processes again. Ultimately this makes developers more productive, agile, disciplined, and focused on the work at hand rather than spending time and effort doing grunt work understanding, developing, and configuring yet another non-standard build system.
Maven: Features
- Portable: Maven is portable in nature because it includes:
- Building configuration using maven are portable to another machine, developer and architecture without any effort
- Non trivial: Maven is non trivial because all file references need to be relative, environment must be completely controlled and independent from any specific file system.
- Technology: Maven is a simple core concept that is activated through IoC container (Plexus). Everything is done in maven through plugins and every plugin works in isolation (ClassLoader). Plugings are downloaded from a plugin-repository on demand.
The primary goal of maven is to allow the developers to comprehend the complete state of a project in the shortest time by using easy build process, uniform building system, quality project management information (such as change Log, cross-reference, mailing lists, dependencies, unit test reports, test coverage reports and many more), guidelines for best practices and transparent migration to new features. To achieve to this goal Maven attempts to deal with several areas like:
- It makes the build process easy
- Provides a uniform building system
- Provides quality related project information
- Provides guidelines related to development to meet the best goal.
- Allows transparent migration to new features.
Maven 2.0 was first released on 19 October 2005 and it is not backward compatible with the plugins and the projects of maven1. In December 2005, a lot of plugins were added to maven but not all plugins that exists for maven1 are ported yet. Maven 2 is expected to stabilize quickly with most of the Open Source technologies. People are introduced to use maven as the core build system for Java development in one project and a multi-project environment. After a little knowledge about the maven, developers are able to setup a new project with maven and also become aware of the default maven project structure. Developers are easily enabled to configure maven and its plugins for a project. Developers enable common settings for maven and its plugins over multiple projects, how to generate, distribute and deploy products and reports with maven so that they can use repositories to set up a company repository. Developers can also know about the most important plugins about how to install, configure and use them, just to look for other plugins to evaluate them so that they can be integrated in their work environment.
Maven is the standard way to build projects and it also provides various other characters like clearing the definition of the project, ways to share jars across projects. It also provides the easy way to publish project information (OOS).
Originally maven was designed to simplify the building processes in the Jakarta Turbine project. Several projects were there containing their own slightly different Ant build files and JARs were checked into CVS. An apache group's tool that can build the projects, publish project information, defines what the project consists of and that can share JARs across several projects. The result of all these requirement was the maven tool that builds and manages the java-based-project.