Maven Frequently Asked Questions

How to use Maven for other languages?
Here's some I know of. As to whether they are the most appropriate tool for a given language, form your own opinion.

.Net: NMaven and dotnet-maven-plugin
AspectJ: aspectj-maven-plugin (still Java I know but worth mentioning)
c/c++: native-maven-plugin compile with compilers such as gcc, msvc, etc ...
Google Web Toolkit gwt-maven-plugin
PHP: Maven for PHP
Ruby: Ruby on Maven
Scala: maven-scala-plugin
Flex and Air: Flexmojos
Arbitrary "integrations" can be handled by using the exec-maven-plugin to invoke the relevant compiler and binding the execution to the compile phase.

There are also Maven-like products such as Byldan for .Net

How to C# Project Management with Maven?
Maven is language agnostic and it should be possible to use it with other languages than Java, including C#. For example, the Maven Compiler Plugin can be configured to use the csharp compiler. There is also a .NET Maven plugin and there was a maven-csharp on javaforge.com (seems dead).

But Java is getting most attention and man power and there is not much done with other languages. So, while using Maven with C# is in theory possible, I wouldn't expect much support and feedback from the community (i.e. in case of problem, you'll be alone). I don't know if using Maven for C# would thus be a good idea. I wouldn't recommend it actually (I may be wrong of course).

What is the use of Parent in Maven?

Yes, maven reads the parent POM from your local repository (or proxies like nexus) and creates an 'effective POM' by merging the information from parent and module POM.

One reason to use a parent is that you have a central place to store information about versions of artifacts, compiler-settings etc. that should be used in all modules.

 

How to change the Maven structure ( src/java to src/Javasource)
Here is a sample build section of a POM that can be used to configure the directories.

<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>

Maven compile with multiple src directories
You can add a new source directory with build-helper

<!-- language: xml -->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/generated</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

 

Change source directory in profile maven
According to the documentation, you can change only few <build> parameters in the profile and <sourceDirectory> is not one of them.

I'd configure the main <build> to take sources from path defined by some property (eg. src.dir), set this property to src/main/java and override it in the custom profile:

<project>
...
<properties>
<src.dir>src/main/java</src.dir>
</properties>
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
...
</build>
<profiles>
<profile>
<id>development</id>
<properties>
<src.dir>${project.build.directory}/new-src</src.dir>
</properties>
</profile>
</profiles>
</project>

How to add an extra source directory for maven to compile?

You can use the Build Helper Plugin, e.g:

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>some directory</source>
...
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>





  Call us on +91 700 483 5930   |   +91 700 483 5706     Contact@DevopsSchool.com