Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [m2e-users] Changing "mocks" source dir from test to main classpath in a profile

Thanks for your answer.

 

I could indeed put my mocks in another module, but in order to have the classes deployed in Tomcat with my “mock” mode I still need to add the dependency in a profile (in fact it’s nearly the same – except that it very certainly works…).

 

I know that profiles are subject to never-ending discussions on their goal and use…in our case we’re using them for local development in mocked mode, before deploying the webapps on a server with resources that are unavailable locally (MQ, etc). I think this is a relatively common requirement.

And it works in pure Maven, and apparently not in m2e…

 

Sophie

 

From: m2e-users-bounces@xxxxxxxxxxx [mailto:m2e-users-bounces@xxxxxxxxxxx] On Behalf Of Anders Hammar
Sent: Wednesday, October 02, 2013 3:09 PM
To: Maven Integration for Eclipse users mailing list
Subject: Re: [m2e-users] Changing "mocks" source dir from test to main classpath in a profile

 

Doesn't sound as a good Maven solution. You're trying to create an Ant script solution with Maven, at least from my perspective. Using profiles is normally not the right way to solve things in Maven.

 

Start by moving your mock classes to a separate project/module. You can then reuse that artifact where ever you want. If you want to use it in your unit tests in a project, you declare a test scoped dependency. If you want to include it in your war, you declare a compile scope dependency (or possibly a runtime dep, dependening on your mock solution).

Remember not to use profiles to change the result of the build though. If you want to two flavors of your project, you should create two separate Maven projects.

 

/Anders

On Wed, Oct 2, 2013 at 2:57 PM, Ramel Sophie (BIL) <Sophie.Ramel@xxxxxxx> wrote:

Hello,

I have a problem with m2e (or m2e-wtp ? I'm not too sure): in my project, a profile activated in eclipse changes the way a source directory is added to the build, by adding it to the "main" classpath, while it is in the "test" classpath when the profile is not active.
It works well in Maven (the packaged war contains the class if the profile is active for packaging), but I cannot make this work in Eclipse to deploy on tomcat.

More specifically, I have classes used in a "mock" mode in Tomcat, as well as in unit tests. So without the profile, these classes are added in the "add-test-source" goal, and with the profile active, to deploy in tomcat from Eclipse, these classes are added in the "add-source" goal.
The main configuration for build-helper-maven-plugin is:
<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
                <execution>
                        <id>add-source</id>
                        <phase>validate</phase>
                        <goals>
                                <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                                <sources>
                                        <source>src/mock/java</source>
                                </sources>
                        </configuration>
                </execution>
        </executions>
</plugin>
While in the profile, the configuration is:
<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
                <execution>
                        <id>add-source</id>
                        <phase>validate</phase>
                        <goals>
                                <goal>add-source</goal>
                        </goals>
                        <configuration>
                                <sources>
                                        <source>src/mock/java</source>
                                </sources>
                        </configuration>
                </execution>
        </executions>
</plugin>

My environment is:
* Eclipse Kepler (tested with 4.3.0 and 4.3.1) with m2e and m2e-wtp preinstalled
* Maven 3.0.1
* JDK 1.6
(and this was working in Eclipse 3.7...)

Is this supposed to work or is it a bug?
What could I do to have these projects work locally, without adding my mock classes to the generated war for the "real" deployment? would an option in m2e-wtp to also publish test classpath be a workaround solution?

Thank you for your help,

Sophie
https://www.bil.com/Documents/mail-disclaimer.html

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

 

https://www.bil.com/Documents/mail-disclaimer.html

Back to the top