Archive

Posts Tagged ‘Maven’

Maven snippet – add generated sources to the build

July 21, 2014 Leave a comment

Here’s a maven snippet I found myself looking for many times – adding generated sources to the build.
This tells Maven to include the generated classes as part of the compilation, which ensures any non generated code that depends on them compiles fine, and their corresponding .class files be included in the .jar/.war file.

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

In this case (line #153) – we assume that the sources are generated to target/generated.

Some useful reading material regarding this subject:

Advertisements

Maven-Eclipse-Spring Integration

December 27, 2012 2 comments

In every new project I write I use maven and Eclipse. On most of these projects I use Spring as well – and I’m probably not the only one around doing it.

The problem I always run in to is how to configure everything to work properly – so once I finally got a properly working configuration, I had to write it down:

Simple Configuration – Maven + Eclipse
This configuration in your pom.xml will generate your .project and .classpath files (and a few more).

<plugin>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.9</version>
</plugin>

Slightly Advanced Configuration – Maven + Eclipse
This configuration will also automatically download sources and javadocs of any dependency you add into your project – very useful when working with open source software.

<plugin>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.9</version>
	<configuration>
		<downloadSources>true</downloadSources>
		<downloadJavadocs>true</downloadJavadocs>
	</configuration>
</plugin>

Spring Specific Configuration – Add Support in Eclipse
The additionalProjectnatures and additionalBuildcommands sections add the springnature and springbuilder to the project and allow you to get Spring specific highlights and notifications on your project (e.g. Icons on each class indicating if it is a Spring bean)

<plugin>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.9</version>
	<configuration>
		<additionalProjectnatures>
			<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
		</additionalProjectnatures>
		<additionalBuildcommands>
			<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
		</additionalBuildcommands>
		<downloadSources>true</downloadSources>
		<downloadJavadocs>true</downloadJavadocs>
	</configuration>
</plugin>

The Maven-Eclipse Plugin has a few more configurations and abilities, you can read more about it on http://maven.apache.org/plugins/maven-eclipse-plugin/

%d bloggers like this: