Cannot use Guice 3 with TestNG and Maven

95 views
Skip to first unread message

unguiculus

unread,
Feb 9, 2011, 8:38:02 AM2/9/11
to testng-users
While the Eclipse plugin has been fixed, so Guice 3 can be used with
TestNG, this is not possible with Maven. I use Maven 3 and the latest
Surefire plugin 2.72. In order to run the test process, the Surefire
plugin creates an empty jar file whose manifest has the classpath in
it. This classpath has TestNG and its dependencies first including
Guice 2. As a result, Guice 3 cannot be used and I get lots of errors
because I use JSR 330 annotations and other features which are not
supported by Guice 2.

I think that, in general, TestNG dependencies should not interfere
with the dependencies of the project under test. So, I'd say you
either have to play some classloader tricks to isolate TestNG from the
project under test or repackage the dependencies you use.

Thanks,
Reinhard

Cédric Beust ♔

unread,
Feb 9, 2011, 1:03:45 PM2/9/11
to testng...@googlegroups.com, unguiculus
Hi Reinhard,

TestNG no longer uses Guice internally, so the Guice2 dependency you are seeing must be coming from somewhere else.

-- 
Cédric



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


unguiculus

unread,
Feb 10, 2011, 4:46:57 AM2/10/11
to testng-users
Hi Cédric,

TestNG may not use Guice internally but the dependency is still there.
At least for version 5.14.9. A look at the TestNG pom or the Maven
dependency tree reveals this. Maybe this has changed for version
5.14.10, but I could not test it because it is not yet available on
Maven Central.

Here's an excerpt from the manifest the Surefire plugin creates for
launching the forked process. You can see that TestNG and its
dependencies are first in the classpath:

Class-Path: file:/C:/Dokumente%20und%20Einstellungen/rnaegele/.m2/repo
sitory/org/apache/maven/surefire/surefire-booter/2.7.2/surefire-boote
r-2.7.2.jar file:/C:/Dokumente%20und%20Einstellungen/rnaegele/.m2/rep
ository/org/apache/maven/surefire/surefire-api/2.7.2/surefire-api-2.7
.2.jar file:/C:/Dokumente%20und%20Einstellungen/rnaegele/.m2/reposito
ry/org/testng/testng/5.14.9/testng-5.14.9.jar file:/C:/Dokumente%20un
d%20Einstellungen/rnaegele/.m2/repository/junit/junit/3.8.1/junit-3.8
.1.jar file:/C:/Dokumente%20und%20Einstellungen/rnaegele/.m2/reposito
ry/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar file:/C:/Dokumente%20und%20E
instellungen/rnaegele/.m2/repository/com/google/inject/guice/2.0/guic
e-2.0.jar file:/C:/Dokumente%20und%20Einstellungen/rnaegele/.m2/repos
itory/aopalliance/aopalliance/1.0/aopalliance-1.0.jar file:/C:/Dokume
nte%20und%20Einstellungen/rnaegele/.m2/repository/com/beust/jcommande
r/1.12/jcommander-1.12.jar file:/C:/Dokumente%20und%20Einstellungen/r
naegele/.m2/repository/org/yaml/snakeyaml/1.6/snakeyaml-1.6.jar file:


Reinhard

unguiculus

unread,
Feb 10, 2011, 9:08:51 AM2/10/11
to testng-users
I experimented a little bit more. There are two workarounds:

- Use an older TestNG version (5.11 works).

- Configure the Surefire plugin with forkMode=never, so Maven won't
create a separate process. In this case, normal Maven dependency
resolution seems to apply. TestNG and its dependencies end up at the
end of the classpath, and Guice 2 won't show up on the classpath at
all.

Now, the question is whether this problem is rather a TestNG or a
Surefire one. Anyways, to be on the safe side I think you should shade
or jarjar all the dependencies TestNG needs.

Thanks,
Reinhard

Cédric Beust ♔

unread,
Feb 10, 2011, 1:52:00 PM2/10/11
to testng...@googlegroups.com
Hi Reinhard,

You're right, the dependency on Guice is still there, but it's because TestNG is exposing a new annotation that uses a Guice symbol. So Guice is no longer used internally but Guice is still needed externally because of that dependency (which is the attribute "modules" of the annotation org.testng.annotations.Guice).

Because this is exposed publicly, using jarjar is not an option: this annotation needs to expose the "real" Module symbol, and not a repackaged one.

I'm not quite sure how to avoid this...

-- 
Cédric

unguiculus

unread,
Feb 14, 2011, 2:46:24 AM2/14/11
to testng-users
I started a discussion on the Maven users list regarding this problem:

http://maven.40175.n5.nabble.com/Problems-with-Surefire-TestNG-and-Guice-3-td3384082.html

Cédric Beust ♔

unread,
Feb 14, 2011, 2:54:46 AM2/14/11
to testng...@googlegroups.com
Thanks for the heads up, Reinhard.

By the way, one solution would be switching TestNG to Guice 3, which I can't do until Guice 3 is officially released (I don't believe it is, correct?). This might also cause problems for users who are still on Guice 2, though.

-- 
Cédric

unguiculus

unread,
Feb 14, 2011, 8:16:46 AM2/14/11
to testng-users
Based on the discussion on the Maven Users list I created to following
ticket:

http://jira.codehaus.org/browse/SUREFIRE-699

Still I think TestNG could be improved in this area. IMHO TestNG
should support any Guice version.

On Feb 14, 8:54 am, Cédric Beust ♔ <ced...@beust.com> wrote:
> Thanks for the heads up, Reinhard.
>
> By the way, one solution would be switching TestNG to Guice 3, which I can't
> do until Guice 3 is officially released (I don't believe it is, correct?).
> This might also cause problems for users who are still on Guice 2, though.
>
> --
> Cédric
>
> On Sun, Feb 13, 2011 at 11:46 PM, unguiculus <reinhard.naeg...@mgm-tp.com>wrote:
>
>
>
> > I started a discussion on the Maven users list regarding this problem:
>
> >http://maven.40175.n5.nabble.com/Problems-with-Surefire-TestNG-and-Gu...

Cédric Beust ♔

unread,
Feb 14, 2011, 11:04:12 AM2/14/11
to testng...@googlegroups.com
On Mon, Feb 14, 2011 at 5:16 AM, unguiculus <reinhard...@mgm-tp.com> wrote:
Based on the discussion on the Maven Users list I created to following
ticket:

http://jira.codehaus.org/browse/SUREFIRE-699

Still I think TestNG could be improved in this area. IMHO TestNG
should support any Guice version.

I would be happy to do that but I don't see how this is possible with the way Maven's pom works right now.

If TestNG can only support one Guice version, I think it should be the latest officially released, which is currently 2...

-- 
Cédric

unguiculus

unread,
Feb 15, 2011, 2:25:22 AM2/15/11
to testng-users
Shouldn't it be possible if the Guice dependency had "provided" scope?
In your pom I can see that <scope>provided</scope> is commented out.
Now the question is what Surefire would do with dependencies that have
provided scope.

Reinhard


On Feb 14, 5:04 pm, Cédric Beust ♔ <ced...@beust.com> wrote:

Cédric Beust ♔

unread,
Feb 15, 2011, 2:56:28 AM2/15/11
to testng...@googlegroups.com
It looks like this won't be necessary:


-- 
Cedric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


krosenvold

unread,
Feb 15, 2011, 2:35:51 AM2/15/11
to testng-users
Fixed in http://svn.apache.org/viewvc?view=revision&revision=1070793

I removed an ancient piece of code that was probably introduced to
fix a bug in an ancient version of TestNG, all our integration tests
pass without it so I'm just pretending the ancient problem does not
exist.

An updated 2.7.3-SNAPSHOT has been deployed to repository.apache.org,
and I would appreciate TestNG users giving it a spin.

The release of 2.7.3 is still in 3-4 weeks according to my schedule,
unless someone finds another committer willing to do an earlier
release ;)

Kristian


Cédric Beust ♔

unread,
Feb 15, 2011, 3:05:31 AM2/15/11
to testng...@googlegroups.com
Awesome, thanks Kristian!

-- 
Cedric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


krosenvold

unread,
Feb 15, 2011, 4:24:21 AM2/15/11
to testng-users
It'd still seem like "provided" is the appropriate scope for the
dependency. With 2.7.3 it'll all be controlled by
the project pom.

Kristian

Cédric Beust ♔

unread,
Feb 15, 2011, 11:41:03 AM2/15/11
to testng...@googlegroups.com
Ok I'll make the change.


Kristian

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


Cédric Beust ♔

unread,
Feb 15, 2011, 6:48:18 PM2/15/11
to testng...@googlegroups.com, krosenvold
Done: bump your TestNG version to 5.14.10 and you should get a pom.xml that uses "provided" for its Guice dependency scope.

-- 
Cédric


2011/2/15 Cédric Beust ♔ <ced...@beust.com>



--
Cédric


unguiculus

unread,
Feb 16, 2011, 5:50:12 AM2/16/11
to testng-users
Thanks, Cédric!

On Feb 16, 12:48 am, Cédric Beust ♔ <ced...@beust.com> wrote:
> Done: bump your TestNG version to 5.14.10 and you should get a pom.xml that
> uses "provided" for its Guice dependency scope.
>
> --
> Cédric
>
> 2011/2/15 Cédric Beust ♔ <ced...@beust.com>
>
>
>
> > Ok I'll make the change.
>

unguiculus

unread,
Feb 16, 2011, 5:57:42 AM2/16/11
to testng-users
Just tested 5.14.10. Scope "provided" did the trick. It is working now
even without the Surefire fix.

Cédric Beust ♔

unread,
Feb 17, 2011, 6:48:57 PM2/17/11
to testng...@googlegroups.com, unguiculus, Kristian Rosenvold
On Wed, Feb 16, 2011 at 2:57 AM, unguiculus <reinhard...@mgm-tp.com> wrote:
Just tested 5.14.10. Scope "provided" did the trick. It is working now
even without the Surefire fix.

Fantastic, thank you and Kristian for helping get to the bottom of this.

By the way, I just made a few improvements to the @Guice support in TestNG, take a look at the latest testng-users messages.

--
Cédric


Reply all
Reply to author
Forward
0 new messages