Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to use variables defined in classes within groovy annotations
    primarykey
    data
    text
    <p>I am trying to port some code from the Dropwizard examples from java to groovy. </p> <p>I see that within java, I can use the following code without any issues:</p> <pre><code>package com.example.helloworld; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @Produces(MediaType.APPLICATION_JSON) public class HelloWorldService{ } </code></pre> <p>However, with the groovy compiler ( both 1.8 and 2.0.6 ), the class fails to compile with a noClassFoundException around MediaType.APPLICATION_JSON</p> <p>If I change this code to use the actual string value</p> <pre><code>@Produces('application/json') public class HelloWorldService{ } </code></pre> <p>everything works perfectly.</p> <p>Are there any differences between the way groovy resolves annotations and the way that java does? </p> <p>For completeness, this is part of a gradle project and here is my build.gradle ( the file goes under src/groovy/com/example/helloworld )</p> <pre><code>apply plugin: 'groovy' // Set our project variables project.ext { dropwizardVersion = '0.6.1' } repositories { mavenCentral() } dependencies { compile group: 'com.yammer.dropwizard', name: 'dropwizard-core', version: dropwizardVersion groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.7' } </code></pre> <p>The compilation error is:</p> <blockquote> <p>Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl ... 17 more Caused by: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl at org.gradle.api.internal.tasks.compile.TransformingClassLoader.findClass(TransformingClassLoader.java:47)</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload