Showing posts with label dependency management. Show all posts
Showing posts with label dependency management. Show all posts

Monday, November 12, 2012

Fix Maven Source Version Having No Effect

In a recent article at http://impossible-is-development.blogspot.com/2012/11/basic-maven-project-build-fix-tip.html, I wrote about a trick to get the .classpath file to reflect the src/main/java etcetera build structure. This trick actually helps in another not-to-uncommon situation: unsyncronized source versions.

If you create a new pom.xml, it may happen that there is no Java versions information given. The version can be given in two ways; via some xml using a 'properties' tag, or via more xml. 

Plugin config: 
<build>
<plugins>
<plugin>
maven-compiler-plugin
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin></plugins>
Sorry about the formatting. (Doesn't the Blogger editor suck something awful for quotes and code? ...hmm...can one blog on Github?)

<project.build.source>1.6</project.build.source> <project.build.target>1.6</project.build.target>
(Again, sorry about the formatting.)

Now; if you add this to an existing pom.xml, Eclipse may fail to take note of this change automatically. Maybe it never takes note. In any case, the same solution applies here as in the earlier blog post: just disable and enable dependency management.

Tuesday, November 6, 2012

Basic Maven Project Build Fix Tip

Sometimes, in Eclipse, a maven project will not be properly set up. For instance, when you create a maven project by creating a pom.xml file inside a folder. This can be seen by inspecting the '.classpath' file -- it will contain only these three items (or similar):


<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> 

<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> 

<classpathentry kind="output" path="target/classes"/>


Then, what you do is this: simply "Disable Dependency Management" and then "Enable Dependency Management" from the "Maven" menu in the contextual menu from the project. If you keep the ".classpath" file open, you'll be able to see the what happens.

In the 'Disable' step, the Maven entry disappears:
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
Then, in the 'Enable' step, the entries which enable the build appears:
kind="src" output="target/classes" path="src/main/java"> 
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
 along with the 'MAVEN2_CLASSPATH_CONTAINER' thing mentioned above. Done!

--

Today I discovered that the above maneuver is in fact useful to handle another problem involving mis-synchronization between ".classpath" and the "pom.xml" file. Article forthcoming.