You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Alan Cassar <al...@ricston.com> on 2009/12/15 17:17:39 UTC

Pulling transiting test dependencies

Hi all,
I am new to this list and I have a problem with maven transitive 
dependencies which cannot quite figure out and would appreciate any help.

Well, we have a project, lets call it project-core and it has its own 
pom with its own dependencies, all test dependencies are marked as 
<scope>test</scope>. Also, in the same project, we have the plugin to 
generate the test jar:
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
                 <executions>
                     <execution>
                         <goals>
                             <goal>test-jar</goal>
                         </goals>
                     </execution>
                 </executions>
             </plugin>

I have another project which is a war project and as dependencies I have 
included both project-core as

        <dependency>
            <groupId>xxx</groupId>
            <artifactId>project-core</artifactId>
            <version>${version}</version>
            <scope>compile</scope>
        </dependency>

and also the test jar as:

        <dependency>
             <groupId>xxx</groupId>
            <artifactId>project-core</artifactId>
            <version>${version}</version>
            <scope>compile</scope>
            <type>test-jar</type>
        </dependency>

The transitive dependencies of the project-core are correctly added to 
my lib folder in the war by maven, but the transitive dependencies 
marked as <scope>test</scope> are not. I know that by default these 
dependencies should not be added, but since I added the testing jar, I 
thought that these dependencies should be added. In fact what happens, 
when the war file is deployed, the application fails with ClassNotFound 
exception when classloading the classes in the test jar.

Is it possible somehow to pull in the test transitive dependencies?

Thanks for your help
Alan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Pulling transiting test dependencies

Posted by Alan Cassar <al...@ricston.com>.
any help on this issue?

On 21/12/2009 13:15, Alan Cassar wrote:
> Hi,
> we have decided that we need to write a maven plugin ourselves for 
> this to work. Basically the maven plugin will be doing the following:
>
>   1. List the project dependencies and figure out which dependencies
>      refer to test jars
>   2. Once we got a list of dependencies, we want to download their POM
>      and read the dependency list
>   3. We resolve the dependency list and add these jars to the final WAR
>
> It sounds easy but I have a question to ask. From a dependency, how 
> can I get the MavenProject obejct for that particular dependency in 
> order to in turn identify its dependencies and be able to resolve 
> them? I am talking about the Maven API now.
>
> I am able to get the current project using
>    /**
>     * @parameter expression="${project}"
>     * @required
>     * @readonly
>     */
>    private MavenProject project;
>
> and the direct dependencies using Set<Dependency> dependencies = 
> project.getDependencyArtifacts(); But from a Dependency object, is it 
> possible to get its MavenProject in order to call 
> getDependencyArtifacts() ?
>
> Thanks for your help
> Alan
>
>
> Justin Edelson wrote:
>> I should have been clearer. The test-helper module I described below 
>> can be
>> purely used as a mechanism to group test dependencies (i.e. need not 
>> have
>> any code in it). So you can still keep your tests classes where they 
>> are (in
>> project-core), but simply use test-helper to effectively combine 
>> multiple
>> dependencies.
>>
>> This isn't actually necessary - the simplest solution is to add the test
>> dependencies directly to your war project. Adding the test-helper 
>> module can
>> help to keep these dependencies in sync between the two projects.
>>
>> I'm not aware of any plugin-based solution for this and it seems 
>> unlikely
>> that there is one.
>>
>> Justin
>>
>> On Tue, Dec 15, 2009 at 11:54 AM, Alan Cassar 
>> <al...@ricston.com>wrote:
>>
>>> its not possible for me to split the project into 2 different 
>>> projects, one
>>> holding the tests and the other holding the core. The idea basically 
>>> is we
>>> have project, and we would like to deploy it on an application 
>>> server and
>>> run the junit tests on the app server itself.
>>>
>>> Isn't this doable with a plugin? or it is impossible because it goes
>>> against the maven rules?
>>>
>>> Thanks again
>>> Alan
>>>
>>> Justin Edelson wrote:
>>>
>>>> On Tue, Dec 15, 2009 at 11:17 AM, Alan Cassar <alan.cassar@ricston.com
>>>>> wrote:
>>>>
>>>>> Is it possible somehow to pull in the test transitive dependencies?
>>>>>
>>>>>
>>>>>
>>>> Not directly. What you can do is create another project (say, 
>>>> test-helper)
>>>> and use that as a dependency for both projects, i.e.
>>>>
>>>> test-helper
>>>> |- depends upon junit, easymock, other test dependencies, etc. 
>>>> (compile
>>>> scope)
>>>>
>>>> project-core
>>>> |- depends upon test-dependencies (test scope)
>>>>
>>>> project-web
>>>> |- depends upon project-core:test-jar and test-dependencies (compile
>>>> scope)
>>>>
>>>> The test-helper project could also contain any testing utility code 
>>>> you
>>>> have.
>>>>
>>>> The key point to keep in mind is that even though you can attach any
>>>> number
>>>> of additional artifacts to a Maven project, they will all share a 
>>>> single
>>>> POM
>>>> file including the set of dependencies.
>>>>
>>>> HTH,
>>>> Justin
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Pulling transiting test dependencies

Posted by Alan Cassar <al...@ricston.com>.
Hi,
we have decided that we need to write a maven plugin ourselves for this 
to work. Basically the maven plugin will be doing the following:

   1. List the project dependencies and figure out which dependencies
      refer to test jars
   2. Once we got a list of dependencies, we want to download their POM
      and read the dependency list
   3. We resolve the dependency list and add these jars to the final WAR

It sounds easy but I have a question to ask. From a dependency, how can 
I get the MavenProject obejct for that particular dependency in order to 
in turn identify its dependencies and be able to resolve them? I am 
talking about the Maven API now.

I am able to get the current project using
    /**
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    private MavenProject project;

and the direct dependencies using Set<Dependency> dependencies = 
project.getDependencyArtifacts(); But from a Dependency object, is it 
possible to get its MavenProject in order to call getDependencyArtifacts() ?

Thanks for your help
Alan


Justin Edelson wrote:
> I should have been clearer. The test-helper module I described below can be
> purely used as a mechanism to group test dependencies (i.e. need not have
> any code in it). So you can still keep your tests classes where they are (in
> project-core), but simply use test-helper to effectively combine multiple
> dependencies.
>
> This isn't actually necessary - the simplest solution is to add the test
> dependencies directly to your war project. Adding the test-helper module can
> help to keep these dependencies in sync between the two projects.
>
> I'm not aware of any plugin-based solution for this and it seems unlikely
> that there is one.
>
> Justin
>
> On Tue, Dec 15, 2009 at 11:54 AM, Alan Cassar <al...@ricston.com>wrote:
>
>   
>> its not possible for me to split the project into 2 different projects, one
>> holding the tests and the other holding the core. The idea basically is we
>> have project, and we would like to deploy it on an application server and
>> run the junit tests on the app server itself.
>>
>> Isn't this doable with a plugin? or it is impossible because it goes
>> against the maven rules?
>>
>> Thanks again
>> Alan
>>
>> Justin Edelson wrote:
>>
>>     
>>> On Tue, Dec 15, 2009 at 11:17 AM, Alan Cassar <alan.cassar@ricston.com
>>>       
>>>> wrote:
>>>>         
>>>
>>>       
>>>> Is it possible somehow to pull in the test transitive dependencies?
>>>>
>>>>
>>>>
>>>>         
>>> Not directly. What you can do is create another project (say, test-helper)
>>> and use that as a dependency for both projects, i.e.
>>>
>>> test-helper
>>> |- depends upon junit, easymock, other test dependencies, etc. (compile
>>> scope)
>>>
>>> project-core
>>> |- depends upon test-dependencies (test scope)
>>>
>>> project-web
>>> |- depends upon project-core:test-jar and test-dependencies (compile
>>> scope)
>>>
>>> The test-helper project could also contain any testing utility code you
>>> have.
>>>
>>> The key point to keep in mind is that even though you can attach any
>>> number
>>> of additional artifacts to a Maven project, they will all share a single
>>> POM
>>> file including the set of dependencies.
>>>
>>> HTH,
>>> Justin
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Pulling transiting test dependencies

Posted by Justin Edelson <ju...@gmail.com>.
I should have been clearer. The test-helper module I described below can be
purely used as a mechanism to group test dependencies (i.e. need not have
any code in it). So you can still keep your tests classes where they are (in
project-core), but simply use test-helper to effectively combine multiple
dependencies.

This isn't actually necessary - the simplest solution is to add the test
dependencies directly to your war project. Adding the test-helper module can
help to keep these dependencies in sync between the two projects.

I'm not aware of any plugin-based solution for this and it seems unlikely
that there is one.

Justin

On Tue, Dec 15, 2009 at 11:54 AM, Alan Cassar <al...@ricston.com>wrote:

> its not possible for me to split the project into 2 different projects, one
> holding the tests and the other holding the core. The idea basically is we
> have project, and we would like to deploy it on an application server and
> run the junit tests on the app server itself.
>
> Isn't this doable with a plugin? or it is impossible because it goes
> against the maven rules?
>
> Thanks again
> Alan
>
> Justin Edelson wrote:
>
>> On Tue, Dec 15, 2009 at 11:17 AM, Alan Cassar <alan.cassar@ricston.com
>> >wrote:
>>
>>
>>
>>> Is it possible somehow to pull in the test transitive dependencies?
>>>
>>>
>>>
>> Not directly. What you can do is create another project (say, test-helper)
>> and use that as a dependency for both projects, i.e.
>>
>> test-helper
>> |- depends upon junit, easymock, other test dependencies, etc. (compile
>> scope)
>>
>> project-core
>> |- depends upon test-dependencies (test scope)
>>
>> project-web
>> |- depends upon project-core:test-jar and test-dependencies (compile
>> scope)
>>
>> The test-helper project could also contain any testing utility code you
>> have.
>>
>> The key point to keep in mind is that even though you can attach any
>> number
>> of additional artifacts to a Maven project, they will all share a single
>> POM
>> file including the set of dependencies.
>>
>> HTH,
>> Justin
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Pulling transiting test dependencies

Posted by Alan Cassar <al...@ricston.com>.
its not possible for me to split the project into 2 different projects, 
one holding the tests and the other holding the core. The idea basically 
is we have project, and we would like to deploy it on an application 
server and run the junit tests on the app server itself.

Isn't this doable with a plugin? or it is impossible because it goes 
against the maven rules?

Thanks again
Alan

Justin Edelson wrote:
> On Tue, Dec 15, 2009 at 11:17 AM, Alan Cassar <al...@ricston.com>wrote:
>
>   
>> Is it possible somehow to pull in the test transitive dependencies?
>>
>>     
> Not directly. What you can do is create another project (say, test-helper)
> and use that as a dependency for both projects, i.e.
>
> test-helper
> |- depends upon junit, easymock, other test dependencies, etc. (compile
> scope)
>
> project-core
> |- depends upon test-dependencies (test scope)
>
> project-web
> |- depends upon project-core:test-jar and test-dependencies (compile scope)
>
> The test-helper project could also contain any testing utility code you
> have.
>
> The key point to keep in mind is that even though you can attach any number
> of additional artifacts to a Maven project, they will all share a single POM
> file including the set of dependencies.
>
> HTH,
> Justin
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Pulling transiting test dependencies

Posted by Justin Edelson <ju...@gmail.com>.
On Tue, Dec 15, 2009 at 11:17 AM, Alan Cassar <al...@ricston.com>wrote:

> Is it possible somehow to pull in the test transitive dependencies?
>
Not directly. What you can do is create another project (say, test-helper)
and use that as a dependency for both projects, i.e.

test-helper
|- depends upon junit, easymock, other test dependencies, etc. (compile
scope)

project-core
|- depends upon test-dependencies (test scope)

project-web
|- depends upon project-core:test-jar and test-dependencies (compile scope)

The test-helper project could also contain any testing utility code you
have.

The key point to keep in mind is that even though you can attach any number
of additional artifacts to a Maven project, they will all share a single POM
file including the set of dependencies.

HTH,
Justin

Re: Pulling transiting test dependencies

Posted by Baptiste MATHUS <ml...@batmat.net>.
I don't understand what could be the use-case for including a test-jar in a
"production" project, imo, test folder should always be useful only for the
project it's in.
Apart from that, maybe your problem comes from the "type" tag you're using
in the <dependency> declaration.

In the declaration below, I guess there're several flaws:
* building a test-jar won't install it in the local repo, and also won't
deploy in the remote repo
=> Did you install manually in the repo ?
* once it's been created, are you sure <type>test-jar</type> is the way to
go? I never generated a test-jar myself before. I just tried and saw it
generates ${project.artifactId}-{project.version}-tests.jar.
=> Then shouldn't use <classifier>tests</classifier> and no type (defaults
to jar) instead of what you put?

HTH
Cheers.

2009/12/15 Alan Cassar <al...@ricston.com>

> Hi all,
> I am new to this list and I have a problem with maven transitive
> dependencies which cannot quite figure out and would appreciate any help.
>
> Well, we have a project, lets call it project-core and it has its own pom
> with its own dependencies, all test dependencies are marked as
> <scope>test</scope>. Also, in the same project, we have the plugin to
> generate the test jar:
>            <plugin>
>                <groupId>org.apache.maven.plugins</groupId>
>                <artifactId>maven-jar-plugin</artifactId>
>                <executions>
>                    <execution>
>                        <goals>
>                            <goal>test-jar</goal>
>                        </goals>
>                    </execution>
>                </executions>
>            </plugin>
>
> I have another project which is a war project and as dependencies I have
> included both project-core as
>
>       <dependency>
>           <groupId>xxx</groupId>
>           <artifactId>project-core</artifactId>
>           <version>${version}</version>
>           <scope>compile</scope>
>       </dependency>
>
> and also the test jar as:
>
>       <dependency>
>            <groupId>xxx</groupId>
>           <artifactId>project-core</artifactId>
>           <version>${version}</version>
>           <scope>compile</scope>
>           <type>test-jar</type>
>       </dependency>
>
> The transitive dependencies of the project-core are correctly added to my
> lib folder in the war by maven, but the transitive dependencies marked as
> <scope>test</scope> are not. I know that by default these dependencies
> should not be added, but since I added the testing jar, I thought that these
> dependencies should be added. In fact what happens, when the war file is
> deployed, the application fails with ClassNotFound exception when
> classloading the classes in the test jar.
>
> Is it possible somehow to pull in the test transitive dependencies?
>
> Thanks for your help
> Alan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !