Hi Guys,
i am working on JaxRsAnalyzer task that obviously uses jaxrs-analyzer-gradle-plugin(com.github.grimmjo:jaxrs-analyzer-gradle-plugin:0.2) in order to create swagger.json in the process of having REST API documentation.
Actually my project Structure is like below:
My project-WebApp
:--src/main
: :-->non-rest-API-Classes ---> Classes
: --->REST API - CLASSES -->Jersey REST API classes and related classes
:--------build.gradle
MY Project- EAR:
:--build.gradle
Based on some sample project, jaxrs-alayzer-gradle-plugins-samples, jaxrsanalyzer task creates swagger,json file the output directory that is mentioned in task like below:
-------------------build gradle file for sample project-----------------------
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath ‘com.github.grimmjo:jaxrs-analyzer-gradle-plugin:0.2’
}
}
plugins {
id “java”
}
apply plugin: ‘java’
apply plugin: ‘jaxrs-analyzer-gradle-plugin’
build.dependsOn analyze
repositories {
mavenCentral()
jcenter()
}
group = ‘com.github.grimmjo’
version = ‘0.2’
dependencies {
compile ‘javax:javaee-api:7.0’
}
jaxRsAnalyzer {
// Available backends are plaintext (default), swagger and asciidoc
//backend ‘swagger’, ‘plaintext’, ‘asciidoc’
backend ‘swagger’
// Domain of the deployed project, defaults to “”
domain ‘localhost:8080’
// Comma separated list of Swagger schemes (only for if backend is swagger, defaults to http)
schemes ‘http’, ‘https’
// Enables rendering of Swagger tags (defaults to false -> default tag will be used)
renderTags true
// The number at which path position the Swagger tags will be extracted (defaults to 0)
tagPathOffset 0
// Directory (relative to buildDir) where resources will be generated (defaults to jaxrs-analyzer)
outputDirectory ‘jaxrs-analyzer’
}
--------------build gradle file for sample project end ----------------------
jaxrs-alayzer-gradle-plugins-sample project is a standalone project(not a web project) and it only contains REST API related classes.
build.dependsOn analyze (in the build script)----> This analyze task creates swagger.json for sample project
I am approaching this below process for my project by following the sample project build script to create swagger.json:
The same thing , I want to apply for my project that is Web application.When I am using jaxrsAnalyzer task and “build.dependsOn analyze” task for my project, It is not able to create the swagger.json and it is giving exception of NoClassFoundError of non-rest api class.
So how can I specify classpath that is only pointing REST api classes(non-rest api should be excluded) in the jaxRsAnalyzer task(Note: It is creating build/jaxrs-analyzer" folder, but not swagger.json)
(or) is there any other way to achieve this , I mean REST API Documentation.
My Project Gradle File is like below:
--------------------------- My Project build Gradle file in the Web App project -------------------
buildscript {
repositories {
jcenter()
//mavenLocal()
}
/*repositories {
maven {
//Company nexus URL
}
}*/
dependencies {
classpath 'com.github.grimmjo:jaxrs-analyzer-gradle-plugin:0.2'
/*classpath("com.github.grimmjo:jaxrs-analyzer-gradle-plugin:0.2"){
exclude group: 'com.itextpdf', module: 'itextpdf'
}*/
}
//repositories {
//jcenter()
//}
println "Buildscript classpath: " + project.buildscript.configurations.classpath.asPath
}
plugins {
id ‘war’
}
apply plugin: “jaxrs-analyzer-gradle-plugin”
compileJava.doFirst {
println 'sourceCompatibility: ’ + sourceCompatibility
println 'targetCompatibility: ’ + targetCompatibility
}
build.dependsOn analyze
webAppDirName = ‘WebContent’
//New code
//New Code
sourceSets {
main {
java {
srcDirs = [‘src’]
}
resources {
srcDirs = ['src']
}
}
}
group = ‘com.github.grimmjo’
version = ‘0.2’
dependencies {
implementation 'commons-io:commons-io:2.4'
//This is working
implementation 'com.itextpdf:itextpdf:5.1.3'
//This is for testing
implementation 'com.realobjects:pdfreactor:8.0'
implementation 'log4j:log4j:1.2.16'
//This is added to avoid the error 'package com.ibm.jvm.util does not exist'.That package is in the rt.jar
compileOnly 'com.ibm.jre:rt:1.6.0'
compileOnly 'javax:javaee-api:6.0'
//Websphere server runtime libraries
compileOnly 'com.ibm.jaxws:thinclient:7.0.0'
implementation 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.26'
implementation 'org.glassfish.jersey.inject:jersey-hk2:2.27'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.17'
//This is for testing
implementation 'org.freemarker:freemarker:2.3.28'
}
jaxRsAnalyzer{
println "Classpath: " +sourceSets.main.runtimeClasspath.asPath
//jaxrsPath sourceSets.main.runtimeClasspath.asPath
//from sourceSets.main.output.classesdir
// Available backends are plaintext, asciidoc and swagger (default)
backend 'swagger'
// Domain of the deployed project, defaults to ""
domain 'localhost:9082'
// Comma separated list of Swagger schemes (only for if backend is swagger, defaults to http)
schemes 'http', 'https'
// Enables rendering of Swagger tags (defaults to false -> default tag will be used)
renderTags true
// The number at which path position the Swagger tags will be extracted (defaults to 0)
tagPathOffset 0
// Directory (relative to buildDir) where resources will be generated (defaults to jaxrs-analyzer)
outputDirectory 'jaxrs-analyzer'
}
war {
manifest {
from ‘WebContent/META-INF/MANIFEST.MF’
}
--------------------------- My Project build Gradle file in the Web App project End -------------------
Let me know what change I need to incorporate to create swagger.json file so that I can use it for Rest API documentation
Another approach(Second approach):
Note: I also got another link ( using JaxrsAnalyzerTask
)
But it does not have any sample.If anybody worked on that, that is also helpful for solution