39

we are using Spring 4.0.1.RELEASE in combination with jdk6 (this is fixed). Of course we have done the config in Java with usage of the @PropertySource annotation. This leads to an annoying warning message(s) when we compile the project with gradle:

org\springframework\context\annotation\PropertySource.class(org\springframework\context\annotation:PropertySource.class): warning: Cannot find annotat ion method 'value()' in type 'java.lang.annotation.Repeatable': class file for java.lang.annotation.Repeatable not found

This is caused by the usage of not (in jdk6) existing Repeatable class and I am glad that it's just a warning. I love the clean output of gradle and this is just annoying because it may obfuscate other "real" warnings (like checkstyle...).

Maybe anyone faced the same problem and got a (not so much hack) solution for this situation. I just want to see a clean output again.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
meistermeier
  • 7,942
  • 2
  • 36
  • 45

4 Answers4

28

I think that the problem is that in Spring 4, they use @Repeatable annotation, which has only been introduced in Java 8.

Therefore, if you're not using Java 8 you'll continue to see this problem, at least until this issue will be fixed.

BTW, this is also preventing the usage of @Scheduled annotation in older JDKs than Java 8. I hope it will be fixed soon.

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
AlonL
  • 6,100
  • 3
  • 33
  • 32
  • Yes, this is the reason. Our goal was to get a clean output after all. It's just annoying to get this warnings. I am looking for something like a filter for gradle outputs or similar approach. – meistermeier Apr 07 '14 at 11:53
  • 1
    See the link below, it might be helpful. http://www.javacodegeeks.com/2013/11/how-to-using-propertysource-annotation-in-spring-4-with-java-7.html BTW, you may mark the question as 'answered' if you've got your answer :) – AlonL Apr 08 '14 at 07:32
  • still not fixed in 4.1.0.RELEASE – coderatchet Sep 05 '14 at 04:47
  • 4
    @AlonL This does not prevent the use of `@Scheduled` on older JDKs. It just gives the annoying warning mentioned in the question. I use spring's (version 4.1.1) `@Scheduled` annotation in my Java 7 project and it works fine. – Doron Gold Nov 16 '14 at 18:23
  • Still same in 4.1.6.RELEASE – jox Apr 27 '15 at 11:46
  • same for Spring 4.2.1. – mehere Oct 08 '15 at 10:24
  • same for Spring 4.2.2. – wolf97084 Nov 19 '15 at 17:36
9

Just for the records: Use

@PropertySources(@PropertySource("classpath:path/to/config"))

to get rid of the exception.

Credits goes to: http://www.javacodegeeks.com/2013/11/how-to-using-propertysource-annotation-in-spring-4-with-java-7.html

scheffield
  • 6,618
  • 2
  • 30
  • 31
1

I guess if you just want to get rid of the warning you might be able to achieve this with a custom logger: http://www.gradle.org/docs/current/userguide/logging.html

I'd check the current implementation, and wrap it in something that filters out the warning you want to ignore, forwarding everything else unchanged.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0

A workaround to get rid of the warning below Java 8 is to use the following approach instead of the @Scheduled annotation:

@PostConstruct
public void setupTaskScheduler() throws FileNotFoundException {
    taskScheduler = new ConcurrentTaskScheduler();

    taskScheduler.schedule(new Runnable(...), new CronTrigger("0 0 * * * *"));    
}
Bruno Carrier
  • 530
  • 5
  • 8