New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnnotationDrivenStaticEntityMockingControl in spring-aspects module require javax.persistence.Entity on compiler classpath [SPR-6819] #11485

Closed
spring-issuemaster opened this Issue Feb 9, 2010 · 41 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Feb 9, 2010

Pavel Král opened SPR-6819 and commented

Aspect org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl require for ajc javax.persistence.Entity to be on classpath, hovewer spring-aspect pom.xml doesn't provide such dependency. As workaround one must declare dependency in affected module pom.xml

<dependency>
  <groupId>javax.persistence</groupId>
  <artifactId>persistence-api</artifactId>
  <version>1.0</version>
  <scope>provided</scope>
</dependency>

Affects: 3.0 GA

Attachments:

Issue Links:

  • #16777 JCache dependency in spring-aspects
  • #11943 Spring aspects depends on javax.persistence/persistence-api 1.0. Conflicts with ROO including hibernate-jpa-2.0-api

Referenced from: commits bd88bba, 4ddcd35, 3537810, 99c5a70, 82ec515, d9df50c, 94292ca, 6e516b7

7 votes, 19 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Feb 10, 2010

Juergen Hoeller commented

Well spotted! Spring 3.0.1 does declare that dependency now.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 5, 2010

Andy Clement commented

users are still reporting a problem with this in Spring 3.0.2. See:

http://forum.springsource.org/showthread.php?p=293070#post293070

does this issue need reopening?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 7, 2010

Juergen Hoeller commented

Costin, could you please double-check this one for the 3.0.2 timeframe? I thought I fixed it in 3.0.1 but apparently I didn't...

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 7, 2010

Costin Leau commented

Fixed. In 3.0.1 the dependency was marked as optional meaning clients still had to include the JPA API in their declaration. By marking the dependency as provided, Maven should include the dependency in the classpath w/o downloading it (for those not using JPA). At least in theory...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 27, 2010

Costin Leau commented

Changed the dependency scope to compile - see this AspectJ bugzilla issue for more information regarding aspects and their dependencies : https://bugs.eclipse.org/bugs/show_bug.cgi?id=310506

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 20, 2010

drekbour commented

I have just upgraded to 3.0.3-RELEASE and it appears the JPA dependency is still "optional" in the POM. The problem appears to be that the trunk pom.xml was amended back to "provided" but the Ivy file which generates the release pom was not.

Shouldn't there be some kind of test-case that the ivy-generated POM matches the stored POM file to avoid this (assuming I analyse correctly).

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 24, 2010

Costin Leau commented

What artifact are you using? As far as I can see the pom in Maven central is correct:
http://repo1.maven.org/maven2/org/springframework/spring-aspects/3.0.3.RELEASE/spring-aspects-3.0.3.RELEASE.pom

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 24, 2010

Costin Leau commented

drekbour, I assume you're using the EBR/repository.springsource.com repo. Indeed there's a conversion that takes place for those artifacts (based on the ivy.xml files) which wasn't updated.
I've fixed this and the nightly build should reflect the change - could you please check the next snapshot and see whether it works for you?
Thanks,

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jul 19, 2010

drekbour commented

Yes we use the EBR. Confirmed that 3.0.4.BUILD-SNAPSHOT is fixed.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jul 19, 2010

Costin Leau commented

Excellent. Thanks!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Aug 25, 2010

Nils Schmidt commented

I have a pretty simple example, using @Configurable and context:spring-configured/. I use aspectj-maven-plugin in version 1.3 to build and AspectJ 1.6.9 and Spring 3.0.4 Jars.

Nevertheless, I still get compile errors like "can't determine annotations of missing type javax.persistence.Entity". If I add the shown above workaround to my POM everything is fine. But shouldn't that have become obsolete with the fix in 3.0.4.RELEASE?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 18, 2010

Ed Bras commented

I also upgrade to 3.0.4 and still have the same problem.
I have to include the javax persist api to solve it.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 18, 2010

Costin Leau commented

What version of Maven are you using? So far the reports for the fix have been positive. Maybe changing the dependency from provided to implicit will sort this out. Could you please temporary modify the pom on your end and report back?
I'm assuming there's some dependency problem with the setup which I escapes me.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 18, 2010

Ed Bras commented

Your fast

Maven version: 2.2.1

I use almost all spring dependencies, included without scope in maven.

Part of my pom you can see below.
I removed the provided scope of the aspectj dependencies below but had no effect.
If I remove the entity dependency below, exact the error as reported in this issue (can't determine annotations of missing type javax.persistence.Entity).
If you need more info, please let me know?


                                                                                                    <spring.version>3.0.4.RELEASE</spring.version>		
<aspectj.weaver.version>1.6.8</aspectj.weaver.version>
<aspectj.jrt.version>1.6.8</aspectj.jrt.version>

..
..

<dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-aspects</artifactId>
</dependency>

...
...
..

	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjweaver</artifactId>
		<version>${aspectj.weaver.version}</version> 
                <scope>provided</scope>
	</dependency>

	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjrt</artifactId>
		<version>${aspectj.jrt.version}</version> 
	        <scope>provided</scope>
	</dependency>

	<dependency>
	  <groupId>javax.persistence</groupId>
	  <artifactId>persistence-api</artifactId>
	  <version>1.0</version>
	  <scope>provided</scope>
	</dependency>
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 18, 2010

Costin Leau commented

Could you try Maven 2.0.x.?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 18, 2010

Ed Bras commented

Just tried maven 2.0.11: same problem ...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 18, 2010

Costin Leau commented

Hmm - at this point I don't know why the dependency isn't included since Maven should normally see it. Could you run the mvn dependency plugin (see http://j.mp/92XZBw) and then attach the output? That should give us some indication on why JPA is not plugin in or not, when you refer to Spring aspects.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

I thought I found it as I noticed, by using the dependency tree that still some old 3.0.2. spring jars were indirectly included.
Anyway, no only 3.0.4 jars are used, but still have the same problem :(..
I have attached the output of the command:
....\bv-core>mvn dependency:tree -Dverbose -Dincludes=org.springframework > bla.txt
But doing this with includes=javax.persistence show up empty... It only shows some tree when I include it directly in my pom (the workaround in this issue).
Strange as I see the the spring-aspects pom contains this:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

spring dependency tree output

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

I also tried it again with maven version 2.0.11 (not with all spring 3.0.4. versions) and still got the same error.
The errors I get in the maven output:
I start to wonder if this is the exact same problem that started this issue.. or just slightly different...


D:\Users\Ed\Develop\Projecten\CodeTree\Belastingvriendin\bv-core\src\main\java\com\bv\core\domain\Add
ressHistory.java:0::0 can't determine annotations of missing type javax.persistence.Entity
when weaving type com.bv.core.domain.AddressHistory
when weaving classes
when weaving
when batch building BuildConfig[null] #Files=161 AopXmls=#0
[Xlint:cantFindType]

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

If I remove the scope part of the javax-persistence in the spring-aspectj-3.0.4.RELEASE.pom such that it looks like:


<dependency>
  <groupId>javax.persistence</groupId>
  <artifactId>persistence-api</artifactId>
  <version>1.0</version>
</dependency>

All works fine: in both maven versions and also it's shows up correctly in the dependency tree....
I also tried scope runtime, which gives the same error, whereas it shows a correct dependency tree.

I remember now having this problem in the past as well with maven, that is: jar's aren't included indirectly because of the scope provided and I had to include them manually, same as happen here...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

Did some more trial-and-error and find out that the Eclipse AJDT plugin shows the same error when removing the javax persistence lib as dependency in eclipse.
That is: to be able to CTW during development, I use the AJDT plugin with the spring-aspects.

Note: I use the latest version MyEclipse and the AJDT plugin and do nothing with maven in eclipse through some plugin. So this error doesn't come from maven.
The project setup of the AJDT plugin is simple: I only activate it per-project and add the spring-aspects, that's it, I don't do anything else.

If I remove the spring-aspects of the Aspects path in Eclipse (in the AJDT project preference part), the error is also removed, such that it seems to be related to the spring aspects in some way..

I have attached the error output of the AJDT plugin compiler..

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

Eclipse AJDT plugin compiler error output

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

I was just thinking about my last comment... but I think it has nothing to do with the issue here :(...
I mean: apearantly the persistency api is required as dependency so it's normal that the the AJDT compiler complaints when I remove it.... ;)..

The problem is that it's not included by maven when the scope is provided...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Costin Leau commented

But you mention it also doesn't work if the scope is compile (not mentioned) which is strange since in that the dependency should be included as long as spring-aspects are.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 19, 2010

Ed Bras commented

If the scope is either runtime or provided it doesn't work.
If I remove the scope, it works, which is the same as the scope compile as that's the default.
So with the scope compile it does work.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 21, 2010

Costin Leau commented

Just committed the fix - the JPA dependency should now have compile scope.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 11, 2010

Thomas Risberg commented

This fix seems to break my JPA 2.0 app when all of a sudden some JPA 1.0 APIs appear on the classpath:

/examples/imdb/domain/Actor_Roo_Entity.aj💯0::0 The method createQuery(String) in the type EntityManager is not applicable for the arguments (String, Class<Actor>)
error at return entityManager().createQuery("select count(o) from Movie o", Long.class).getSingleResult();

I guess I could add an exclusion in my pom, but it's auto-generated, so that would be inconvenient.

Any ideas?

-Thomas

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 14, 2010

Juergen Hoeller commented

So what are the options now? We've been trying quite a few over the past few releases, and it seems to me that no matter we do, it's always inconvenient to somebody...

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 14, 2010

Thomas Risberg commented

Personally, I think it is better to leave it as provided and then include an explicit dependency as needed. The error messages would be easier to interpret I think. Using compile would cause trouble for someone using Roo/JPA 2.0 and the error messages aren't as obvious.

-Thomas

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 14, 2010

Juergen Hoeller commented

I'm undecided. The discussion up there strongly suggested 'compile', although personally I was also leaning towards 'provided'. I guess we once again have to evaluate what's the lesser evil here... for a release that's going to be published tomorrow!

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 17, 2010

Stéphane Nicoll commented

I also think <optional>true</optional> (or scope provided but the optional tag is more clean regarding this use case) makes more sense. Especially because these are JPA 1 APIs. From my experience, it's always much more painful to add an exclude to some project instead of adding an optional dependency because we use an optional feature of that library.

Also, maybe it was said previously but provided is NOT transitive.

I would go for

<dependency>
  <groupId>javax.persistence</groupId>
  <artifactId>persistence-api</artifactId>
  <version>1.0</version>
  <optional>true</optional>
</dependency>
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 19, 2010

Juergen Hoeller commented

I've finally declared the dependency as optional again, consistently with the spring-orm dependency. Since we have JpaExceptionTranslatorAspect as well in the meantime, we do need the JPA API dependency, but formally only as optional - when actually relying on it at runtime, it needs to be manually included (using your JPA API version of choice).

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 15, 2010

Graham Thomson commented

I encountered this same issue today, using Spring 3.0.5.RELEASE. The workaround of including the provided scope dependency is still necessary at this version.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 15, 2010

Stéphane Nicoll commented

I think you reopened this issue by mistake. Maybe the status of the issue should be "won't fix" instead of "complete".

Reading the whole threads and the last comments might help.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 18, 2011

Ats U. commented

I think this issue needs to be reopened and solved properly.

I encountered the same issue. Yes, I could work around it as suggested by adding optional/provided or what ever scope dependency to my project, but I think this is not correct solution.

Costin Leau referred to AspectJ issue, that is directly related to this issue - now it is resolved https://bugs.eclipse.org/bugs/show_bug.cgi?id=310506#c2

It seems to me that now this issue could be correcty reolved because of enhancement for AspectJ issue 310506.
As I understood correct way to solve this issue is to define, that aspect that is causing this issue should be switched off if javax.persistence.Entity class is not available:

<aspect name="org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl" requires="javax.persistence.Entity"/>

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 5, 2011

Antti Andreimann commented

I would also LOVE to see the previous fix implemented. It's much cleaner than any workaround.

Roo projects without persistence also suffer from this bug:

  1. Create a new Roo project
  2. Run web mvc setup
  3. Create a controller: eg web mvc controller --class ~.web.TestController

And BANG!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 23, 2012

Winarto commented

Even in 3.1.3, I still get this error

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 15, 2013

Peter De Winter commented

Yup, 3.1.2 too... .

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jul 23, 2014

Hantsy Bai commented

Encountered this problem in the latest Spring 4.0.6.

I am using MongoDB as data storage, and use Spring Data MongoDB for data persisting, it is unreasonable to add JPA in dependencies.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 24, 2014

Stéphane Nicoll commented

AspectJ 1.8.3 provides a new annotation to disable an aspect that requires a dependency that is not present. We now use this annotation on AnnotationDrivenStaticEntityMockingControl to require javax.persistence.Entity.

If you want to benefit from this feature, you should also update your build to use Aspect 1.8.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment