Swagger API documentation in Play application with Gradle - scala

I'm developing a Play application in Scala as a hobby project. I'm using Gradle as a building tool.
I want to generate API documentation using swagger. My goal is to generate swagger.json file containing my REST API documentation in JSON format with Gradle task during build of the project.
To generate the swagger file I'm using swagger-gradle-plugin. I have annotated controllers and methods in the controllers with proper annotations from swagger.io.swagger_play library.
Unfortunately, play annotations are not recognized by the plugin. File swagger.json generated using Gradle resolve task only picks up JAX-RS annotations I put in the controllers when trying to make plugin work.
For example, when I annotated a controller with
#Api(value="testController", tags = Array("Test controller")
annotation, the resolve task produced empty swagger.json file.
When I annotated the controller with JAX-RS annotation
#Path("/")
and then added JAX-RS annotations to the method inside the controller
#GET
#Path("testEndPoint1")
resolve task generated documentation for /testEndPoints1. But annotations from swagger.io.swagger_play are still ignored so there is not much information in the generated documentation.
I saw there are some plugins for sbt, but I want to make it work using Gradle.
Is there any way I can generate swagger REST API documentation in Play application while using Gradle building tool?
Versions of the tools in the project:
Play 2.8
Gradle 6.5.1
Scala 2.12
io.swagger.core.v3.swagger-gradle-plugin 2.1.6
io.swagger:swagger.play_2.12:1.7.1
EDIT:
Gradle configuration of the plugin:
resolve {
outputFileName = "swagger"
outputDir = "build/swagger_doc"
classpath = sourceSets.main.runtimeClasspath
readAllResources = true
openApiFile = file("openapi_config.yaml")
}

Related

How to load selected beans from external library in micronaut

I'm used to creating custom Spring Boot based libraries with a number of different beans per library. A target Spring Boot app then would use #Import to make a subset of those Beans available w/out importing all of the beans from an external library. An external library would also include spring integration tests (i.e. #SpringBootTest).
I'm trying to replicate this functionality in Micronaut. I've created an external library using 'io.micronaut.library' gradle plugin. It also contains some micronaut integration tests (i.e. #MicronautTest).
Per https://docs.micronaut.io/latest/guide/#beanImport I expected none of the beans to be imported by default. However, I've noticed that a class annotated with #Singleton was imported by default. I suspect this is due to its inclusion in the META-INF/services/io.micronaut.inject.BeanDefinitionReference within the library jar. If I remove META-INF/services/io.micronaut.inject.BeanDefinitionReference from the jar manually then none of the beans are imported by default and I can use explicit #Import to import what is needed.
The package of the library is com.some.micronaut.http while application package is com.some.somethingelse so the namespaces do not match. Both the library and the application are written in Kotlin.
Is there a way to control which beans are imported from an external library? Or can I control which bean references are included in META-INF/services/io.micronaut.inject.BeanDefinitionReference?
Here is a relevant build.gradle portion from the external library:
plugins {
id("org.jetbrains.kotlin.jvm") version "${kotlinVersion}"
id("org.jetbrains.kotlin.kapt") version "${kotlinVersion}"
id("org.jetbrains.kotlin.plugin.allopen") version "${kotlinVersion}"
id 'io.micronaut.library' version "3.1.1"
}
dependencies {
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-jackson-databind")
//test
testImplementation 'io.micronaut.test:micronaut-test-junit5'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
//wiremock for http client tests
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.32.0'
}
I'm flexible about usage of io.micronaut.library plugin but I do need to be able to run #MicronautTest as part of the library build.
For now, I've removed META-INF/services/io.micronaut.inject.BeanDefinitionReference from the library jar explicitly in my build.gradle:
jar {
exclude('META-INF/services/io.micronaut.inject.BeanDefinitionReference')
}
and then used #Import in my application to explicitly import the desired components. I've also submitted an enhancement request.

How to get list of all JARs dependent by a Gradle app project?

Given a Java or Scala application built using Gradle and dependencies defined by Gradle, is it possible to create a task that simply generates a list of all JARs (with versions in file name) that are dependent by the app and required to run the application?
add 'project-report' plugin will add tasks for dependency report generation html/txt
https://docs.gradle.org/current/userguide/project_report_plugin.html

Eclipse PDE/OSGi: Reflections Library not finding packages

The org.reflections library does not function correctly when it's used inside an Eclipse Plugin project.
For instance, the following code should return all classes of a given subtype in a given package:
Reflections reflections = new Reflections("my.package");
Set<Class<? extends Subtype>> classes = reflections.getSubTypesOf(Subtype.class);
When running the project as a Plugin, classes will be empty. Inserting a main() and running it as a normal Java application will correctly return the expected classes.
I've tried to:
Include the Reflections library as a normal third-party jar dependency
Include the Reflections library as an OSGi bundle (http://stackoverflow.com/questions/8339845/reflections-library-not-working-when-used-in-an-eclipse-plug-in)
Edit: current process (based on stackoverflow answer above):
1) New Plugin-Project (OSGIReflections called) based on external JARs (Reflections and Javassist)
2) In my actual Plugin-project (X) I add a dependency on OSGIReflections in Dependencies -> Required Plug-ins
2.a) If I run the project as normal java app: Reflections is working
2.b) If I run the project as plugin project: Reflections is not working
3) Create the BundleUrlType class
4) How do I activate this BundleUrlType? In my plugin Activator I call the createReflections(context.getBundle()) function but I do not have a .data file. How do I generate that?

Spring 3.1 NoClassDefFoundError ListableBeanFactory

I am trying to upgrade an old project from Spring 2.5.6 to Spring 3.1.0. The project is not built with Maven so I had to add the jars manually to the build path.
The application uses Eclipse RAP as well as Spring.
I added all the Spring 3.1 jars in my build path:
lib/org.springframework.aop-3.1.0.RELEASE.jar
lib/org.springframework.asm-3.1.0.RELEASE.jar
lib/org.springframework.aspects-3.1.0.RELEASE.jar
lib/org.springframework.beans-3.1.0.RELEASE.jar
lib/org.springframework.context-3.1.0.RELEASE.jar
lib/org.springframework.context.support-3.1.0.RELEASE.jar
lib/org.springframework.core-3.1.0.RELEASE.jar
lib/org.springframework.expression-3.1.0.RELEASE.jar
lib/org.springframework.instrument-3.1.0.RELEASE.jar
lib/org.springframework.instrument.tomcat-3.1.0.RELEASE.jar
lib/org.springframework.jdbc-3.1.0.RELEASE.jar
lib/org.springframework.jms-3.1.0.RELEASE.jar
lib/org.springframework.orm-3.1.0.RELEASE.jar
lib/org.springframework.oxm-3.1.0.RELEASE.jar
lib/org.springframework.test-3.1.0.RELEASE.jar
lib/org.springframework.transaction-3.1.0.RELEASE.jar
lib/org.springframework.web-3.1.0.RELEASE.jar
lib/org.springframework.web.portlet-3.1.0.RELEASE.jar
lib/org.springframework.web.servlet-3.1.0.RELEASE.jar
lib/org.springframework.web.struts-3.1.0.RELEASE.jar
and I also listed them in the MANIFEST.MF.
The project builds fine, but at runtime when trying to login it gives me the following error:
java.lang.NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory
I looked in the beans jar and the class is definitely there. I also searched through the project and the class is not used explicitly anywhere.
What could cause this? Thank you in advance.
This class does not exist in Spring 3.1.0. See http://www.jarfinder.com/index.php/java/info/org.springframework.beans.factory.ListableBeanFactory

Unable to generate metamodel definitions using DataNucleus JPACriteriaProcessor from Eclipse

I'm trying to generate the metamodel definitions in Eclipse as documented on:
http://www.datanucleus.org/products/accessplatform/jpa/jpql_criteria.html
My project compiler level is set to 1.6 and the mentioned datanucleus jars are added to the factory path.
When the project builds I get the following error:
Errors occurred during the build.
Errors running builder 'Java Builder' on project 'X'.
Could not initialize class org.datanucleus.jpa.query.JPACriteriaProcessor
When using mvn compile the metamodel definitions are generated successfully, so it's probably related to Eclipse annnotation processing.
I'm using latest Spring Tool Suite 3.1.0.RELEASE based on Eclipse 4.2.1
Not put persistence-api.jar (or equivalent, such as Geronimo specs JPA2) in the Factory Path? Either way one of the deps is missing