Using Micronaut OpenAPI/Swagger generator with grails 4 - swagger

We're considering using grails 4.0.0 for our project, and i see that this new version has Micronaut as new parent application context, and that many Micronaut features are handled (seen in grails doc: http://docs.grails.org/latest/guide/introduction.html#micronautSupport)
We would like to use the Micronaut Swagger/OpenAPI documentation generator feature (https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html) with grails, and would like to know if this is possible.
I tried it on a grails 4 project by adding the right dependecies and use the Micronaut and Swagger V3 annotations, but it does not work when i run the grails app (no *.yml generated in the the META-INF/swagger)
The micronaut dependecies:
annotationProcessor "io.micronaut:micronaut-validation"
annotationProcessor "io.micronaut.configuration:micronaut-openapi"
compile "io.micronaut:micronaut-inject"
compile "io.micronaut:micronaut-validation"
compile "io.micronaut:micronaut-runtime"
compile "io.swagger.core.v3:swagger-annotations"
compile "io.micronaut:micronaut-http-client"
compile "io.micronaut:micronaut-http-server-netty"
Thank you very much!

Adding the following under dependencies in build.gradle solved the issue for me (in Micronaut, not tested with Grails)
annotationProcessor "io.micronaut.configuration:micronaut-openapi:1.4.0"
compile "io.swagger.core.v3:swagger-annotations:2.1.1"
compileOnly "io.micronaut.configuration:micronaut-openapi:1.4.0"
notice the compileOnly "io.micronaut.configuration:micronaut-openapi:1.4.0" that is missing in your dependency declaration!

As Grails is Groovy I don't think that you need the "annotationProcessor" line. All of the Micronaut documentation that I've seen states that when using Groovy "annotationProcessor" is replaced by "compileOnly". I also found that I needed to provide the version numbers. I first copied the lines from a Micronaut project, which didn't have version numbers, and it didn't work.

Related

How can I read a Grails 2.x project dependencies programmatically?

I have a Grails 2.x project with a BuildConfig.groovy, and I need to read the dependencies programmatically, using some kind of API that will process the file so that I can read how it would be at runtime. So far I have been unable to locate the right class in the Grails API for processing a BuildConfig.groovy.
How can I do this?
Thanks
Use this simple command to generate your dependency report -
grails dependency-report runtime
reference - doc

Grails 3: what is replacement for eventCreateWarStart in _Events.groovy

I am migrating a plugin from Grails 2.4 to Grails 3. I am facing to the following issue.
I tried to use eventCreateWarStart in _Events.groovy. Like we used to compile widgetset in our plugin's _Events.groovy file. But it seems this approach is not allowed in Grails 3.
I went through the specification and I have not found what is the replacement. Can anyone help?
In general you cannot use concepts from the old build 2.x build system and have to instead write a Gradle plugin.
For example your requirements sound very similar to the asset pipeline plugin which modifiers Gradle's war task to include compiled static assets (see https://github.com/bertramdev/asset-pipeline-core/blob/master/asset-pipeline-gradle/src/main/groovy/asset/pipeline/gradle/AssetPipelinePlugin.groovy#L91)

install spring-security-core plugin into plugin, which then is installed in application

I've just switched to grails 2.2 and have got a major plugin problem. I've got an application - my-app and a plugin - my-plugin. I want to install spring-security-core plugin into my-plugin, and then install my-plugin into my-app. When I've done this and did s2-quickstart, so that LoginController got created. I can start my-plugin with no problems now, but when I try to start my-app it complains that it cannot find any springsecurity classes. Errors looks like this:
12: unable to resolve class org.springframework.security.web.WebAttributes # line 12, column 1.
7: unable to resolve class org.springframework.security.authentication.AccountExpiredException # line 7, column 1.
11: unable to resolve class org.springframework.security.core.context.SecurityContextHolder # line 11, column 1.
It looks to me, like only my-plugin can see spring security plugin dependencies, and my-app cannot, so they didn't cascade even thought according to manual they should have.
I've also tryed to install spring-security-core plugin by adding in BuildConfig.conf this:
compile ":spring-security-core:1.2.7.3"
but it didn't work either.
Any ideas?
If you use install-plugin in a plugin, it's only installed locally by adding a line in application.properties. It doesn't get exported as a dependency of your plugin. This could be used for plugins like code-coverage where you want to use it during development and testing but not force users to also install it.
In older versions of Grails the dependsOn map in the plugin descriptor was used to express plugin dependencies. This is now deprecated in favor of dependencies registered in the plugins secton of BuildConfig.groovy. This is both for consistency and to take advantage of the more fine-grained features supported by the dependency DSL including specifying scopes and exclusions. This is also true for applications - don't use install-plugin for either apps or plugins, always use BuildConfig.groovy.
Take a look at the spring-security-ldap plugin's BuildConfig.groovy. It has a compile-scope dependency on the core plugin, plus one for the hibernate plugin that's not exported (since it's just for testing) and a build-scope dependency on the release plugin (also not exported since it's just used to release the plugins).
You should probably using a similar dependency on the core plugin in your BuildConfig.groovy. Delete any plugin references in your application.properties and convert to BuildConfig.groovy syntax and run grails clean followed by grails compile.
Thank you Burt for your advice. I've used it and here's what I came to:
I created a plugin-app and installed spring-security-core plugin in it (using DataSource.groovy, and not install plugin). Then I created a main-app and installed my plugin-app (again using DataSource.groovy). When I did this in grails 2.1.1 everything worked just fine - I could use spring-security in my main-app, so the dependency got pulled just right. When I did everything the same, but in grails 2.2 I couldn't use spring-security in my main-app, so dependencies didn't get pulled. That's why I think this might be some kind of a bug in new grails version.

Can I use Grails Plugin classes outside a Grails project as a Jar dependency?

I have found some code in grails plugins that can be use outside grails. Is there a way to use the code from the plugin as a dependency in a groovy project other than creating two projects?
For example I found the following project:
https://github.com/jeffellis/grails-yammer-metrics
Where they created some annotations for Groovy code that I would like to use outside a grails project.
As of grails 2.1, you can export a plugin as a binary plugin and then declare as a regular jar dependency (via grape in groovy). http://grails.org/doc/latest/guide/plugins.html#binaryPlugins
How reusable the code is would depend on how closely coupled the plugin is to the code, I guess.

how to get version 4.0 of httpclient off of my classpath in grails

I am using Grails 1.3.7 and cannot figure out how to get version 4.0 of httpclient off of my classpath (in favour of 4.1). I need to do this because of a no-args constructer used in 4.1 that the plugin relies on.
Running a grails 'dependency-report', it appears that 4.1 should be the one being used at runtime. And it IS, if I package things up into a .war. HOWEVER version 4.0 is still ending up on the classpath when using run-app for some reason. Note it is (correctly) being used at compile time for some grails internals, and somehow it is still ending up on my classpath.
-> Can I figure out where exactly that 4.0 .jar is coming from and ending up on my classpath and stop it from happening (where are all the .jars put when running via run-app?)
-> Can I tell grails to compile with 4.1 instead of 4.0 for its internals (in this case the http-builder by org.codehaus.groovy.modules.http-builder module?) Arguable not the best solution but I'll take it, as packaging everything into a .war every time I want to test it is not pleasant.
Help would be greatly appreciated.
I just went through the same thing, add the following to your BuildConfig.groovy
dependencies {
build 'org.apache.httpcomponents:httpcore:4.1.2'
build 'org.apache.httpcomponents:httpclient:4.1.2'
runtime 'org.apache.httpcomponents:httpcore:4.1.2'
runtime 'org.apache.httpcomponents:httpclient:4.1.2'
}
cheers
Lee
You can get httpclient 4.0 off of the classpath by adding an excludes line in BuildConfig.groovy. Figure out which plugin is declaring it as a dependency by using the grails dependency-report command.
Once you find which one included it, you can exclude it in the plugins section of BuildConfig.groovy. Example:
plugins {
compile ':other-plugin:1.0.0' // other-plugin depends on httpclient 4.1
compile(':aws:1.2.12.2') { // aws plugin depends on httpclient:3.1
excludes 'httpclient'
}
}
The plugin that relies on the no-arg constructor in httpclient 4.1 should declare it as a dependency. If it does not you should open an issue with the author of the plugin. To workaround this, you can list httpclient 4.1 in the dependencies section as leebutts describes above.

Resources