问题
I have a trait:
trait AbstractSender {
abstract SentTrigger sendMail(Mail main)
SentTrigger sentTrigger(Mail mail){
//do smth here
}
}
And I have a class:
class EmailSender implements AbstractSender{
@Override
SentTrigger sendMail(Mail mail){
//do some stuff
}
}
I try to compile it using gmavenplus plugin:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- any version of Groovy \>= 1.5.0 should work here -->
<version>2.4.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
and get compile exception:
EmailSender is not abstract and does not override abstract method sentTrigger in AbstractSender
method sentTrigger is implemented. Generated java code looks this way:
@groovy.transform.Trait() public interface AbstractSender
{
;
SentTrigger sendMail(Mail mail);
sentTrigger sentTrigger(Mail mail);
}
Which does explain compilation error. What do I do wrong with gmavenplus plugin?
回答1:
It's not a GMavenPlus configuration issue. You can put this in your GroovyConsole to demonstrate this
trait AbstractSender {
abstract SentTrigger send(Mail main)
SentTrigger sentTrigger(Mail mail) { }
}
class EmailSender implements AbstractSender{
@Override
SentTrigger sendMail(Mail mail) { }
}
class Mail { }
class SentTrigger { }
new EmailSender()
The error message you're seeing is correct. EmailSender
only implements sendMail()
, not send()
. If you rename sendMail()
to send()
, it should compile correctly.
来源:https://stackoverflow.com/questions/32224258/cant-compile-trait-using-gmavenplus-plugin