Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [m2e-dev] [m2e-users] Target folder outside project's folder -> JUnit does not work

You need to have m2e extensions development environment as explained in
[1]. Alternatively you can use m2e development environment as explained
in [2].

You will need to implement org.eclipse.m2e.core.projectConfigurators
extension.

Subclass org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator in
your implementation and override #getOutputLocation method to return
whatever location you need.

In (parent) pom of your project define m2e lifecycle mapping
configuration that maps maven-compiler-plugin to your new project
configurator. Configuration format is explain in [3] and you can use
standard m2e mapping [4] as an example.

Hope this helps and if you have more questions, please ask on m2e-dev
mailing list.


[1] http://wiki.eclipse.org/M2E_extension_development_environment
[2] http://wiki.eclipse.org/M2E_Development_Environment
[3] http://wiki.eclipse.org/M2E_plugin_execution_not_covered
[4] http://git.eclipse.org/c/m2e/m2e-core.git/tree/org.eclipse.m2e.jdt/lifecycle-mapping-metadata.xml?id=releases/1.4/1.4.0.20130601-0317

--
Regards,
Igor

On 2013-08-22 10:34 AM, Lucas Persson wrote:
Thanks Igor

I will happily receive pointer to implement a java project configurator.
Cheers
Lucas
22 aug 2013 kl. 16:10 skrev Igor Fedorenko <igor@xxxxxxxxxxxxxx>:

It is not possible to configure m2e to do what you want and generally
m2e only supports projects that are fully contained under their base
directory. You should be able to implement alternative java project
configurator that will configure classpath like you need. I can provide
pointers on m2e-dev if you want to try.

--
Regards,
Igor

On 2013-08-22 9:20 AM, Lucas Persson wrote:
Hi

I have defined that the target folder (and target/classes) shall be outside the project's folder.
The reason to have it like this is that I am using a proprietary SCM which do not allow write access unless a file is checkout out.
And als it does not have any type of "ignore" filter.

The thing is that every time I do "Maven->Update Project..." it fails like this:

An internal error occurred during: "Updating Maven Project".
Path must include project and resource name: /tiget-api

java.lang.IllegalArgumentException: Path must include project and resource name: /tiget-api
	at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
	at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2163)
	at org.eclipse.core.internal.resources.Container.getFolder(Container.java:222)
	at org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping.configure(AbstractLifecycleMapping.java:71)



I am not sure what m2e does here but I guess it is updating the output folder (among other things)

It seems that if I do not use target folders outside the project's folder the "Maven->Update Project..." succeeds.

The real only issue I can see after that "Maven->Update Project..." fails is that when I try to run JUnit then the Junit launch classpath is not including the target/classes and target/test-classes folders. So JUnit will always end up in class not found for the test class.


So in the root pom(parent pom) I have something like this:	


   <properties>
     <rootTargetDirectory>${env.M2_TARGET}</rootTargetDirectory>
     <targetDirectory>${rootTargetDirectory}/${project.groupId}/${project.artifactId}/target</targetDirectory>
....

   <build>
     <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
     <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
     <directory>${targetDirectory}</directory>
     <outputDirectory>${targetDirectory}/classes</outputDirectory>
     <testOutputDirectory>${targetDirectory}/test-classes</testOutputDirectory>
....


And in order to make sure the both Eclipse and Maven compiles to same output folder I have it like this in .classpath and .project

<classpath>
   <classpathentry kind="src" path="src/main/java"/>
   <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
   <classpathentry kind="output" path="target/classes"/>
</classpath>

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>tiget-api</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.m2e.core.maven2Builder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
	</natures>
	<linkedResources>
		<link>
			<name>target</name>
			<type>2</type>
			<locationURI>M2_TARGET/tiget.core/tiget-api/target</locationURI>
		</link>
	</linkedResources>
</projectDescription>

And M2_TARGET is a Eclipse "Linke resource" path variable which all developers in my team needs to defined in their workspace.

So this works very well until we started to use m2e plugin for dependency management.



So basically is there some way to configure m2e to for instance not updating the output folder?
Or can I make some sort of extension to m2e to fix this?



I am using m2e plugin of 1.4 in Eclipse Indigo


Thanks
Lucas
_______________________________________________
m2e-users mailing list
m2e-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/m2e-users

_______________________________________________
m2e-users mailing list
m2e-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/m2e-users

_______________________________________________
m2e-users mailing list
m2e-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/m2e-users



Back to the top