Swagger2Markup / spring-swagger2markup-demo

A demo project template using Swagger2Markup, Spring Boot, Springfox and spring-restdocs
397 stars 259 forks source link

Pdf is not generated #5

Closed ashwanikumar04 closed 8 years ago

ashwanikumar04 commented 8 years ago

Hello: I am following the same code which is in the demo repository. I am able to generate the .adoc file but PDF file is not generated. Following is my gradle settings


test {
    systemProperty 'io.springfox.staticdocs.outputDir', swaggerOutputDir
}

convertSwagger2markup {
    dependsOn test
    inputDir swaggerOutputDir
    pathsGroupedBy io.github.robwin.swagger2markup.GroupBy.TAGS
}

asciidoctor {
    dependsOn convertSwagger2markup
    sources {
        include 'index.adoc'
    }
    backends = ['html5', 'pdf']
    attributes = [
            doctype    : 'book',
            toc        : 'left',
            toclevels  : '3',
            numbered   : '',
            sectlinks  : '',
            sectanchors: '',
            hardbreaks : '',
            generated  : asciiDocOutputDir
    ]
}

In the logs I get

:convertSwagger2markup
reading from /home/ashwani/project/test/build/swagger/swagger.json
:asciidoctor UP-TO-DATE

BUILD SUCCESSFUL

I am not sure what is wrong in my configuration. Please have a look. Thanks, Ashwani

RobWin commented 8 years ago

Hi,

If the AsciiDoctor task thinks he is up-to-date than run gradlew clean asciidoctor

I hope this helps.

RobWin commented 8 years ago

If you use Swagger2markup, I would love to get your GitHub Star in the code project https://github.com/Swagger2Markup/swagger2markup

ashwanikumar04 commented 8 years ago

Hi, RobWin Already starred it :+1:

I always run the same command which you gave. But still getting the same output. i.e. no pdf :(

RobWin commented 8 years ago

Could you show me your Full gradle Script?

ashwanikumar04 commented 8 years ago

Here it is

buildscript {
    ext {
        springBootVersion = '1.3.0.RELEASE'
        snippetsDir = file('build/generated-snippets')
    }
    ext['hibernate.version'] = '5.0.4.Final'
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
        classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10.1'
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.0.RELEASE'
        classpath 'io.github.robwin:swagger2markup-gradle-plugin:0.9.1'
        classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.asciidoctor.convert'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.github.robwin.swagger2markup'
jar {
    baseName = 'test'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
    maven { url 'https://repo.spring.io/snapshot' }
    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
    mavenLocal()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.security.oauth:spring-security-oauth2:2.0.7.RELEASE')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.postgresql:postgresql:9.4-1201-jdbc41')
    compile('javax.inject:javax.inject:1')
    compile "io.springfox:springfox-swagger2:2.2.2"
    compile("io.springfox:springfox-swagger-ui:2.1.1")
    compile('net.kencochrane.raven:raven-logback:6.0.0')
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.1")
    compile('org.projectlombok:lombok:1.12.6')
    compile('org.hibernate:hibernate-java8:5.0.4.Final')
    testCompile 'io.springfox:springfox-swagger2:2.2.2'
    testCompile 'org.springframework.boot:spring-boot-starter-test'
    testCompile 'io.springfox:springfox-staticdocs:2.2.3-SNAPSHOT'
    testCompile 'junit:junit'
    testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc'
    testCompile 'com.fasterxml.jackson.module:jackson-module-jsonSchema:2.4.0'
    testCompile 'io.github.robwin:assertj-swagger:0.1.2'
}

eclipse {
    classpath {
        containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
        containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.7'
}

ext {
    asciiDocOutputDir = file("${buildDir}/asciidoc")
    swaggerOutputDir = file("${buildDir}/swagger")
}

test {
    systemProperty 'io.springfox.staticdocs.outputDir', swaggerOutputDir
}

convertSwagger2markup {
    dependsOn test
    inputDir swaggerOutputDir
    pathsGroupedBy io.github.robwin.swagger2markup.GroupBy.TAGS
}

asciidoctor {
    dependsOn convertSwagger2markup
    sources {
        include 'index.adoc'
    }
    backends = ['html5', 'pdf']
    attributes = [
            doctype    : 'book',
            toc        : 'left',
            toclevels  : '3',
            numbered   : '',
            sectlinks  : '',
            sectanchors: '',
            hardbreaks : '',
            generated  : asciiDocOutputDir
    ]
}
RobWin commented 8 years ago

Thx. I have some findings:

  1. If you want to use Spring Boot v1.3.0, you need Springfox v2.3.0. The v2.2.2 does not work with Spring Framework 4.2.X.
  2. You don't need testCompile 'io.github.robwin:assertj-swagger:0.1.2' for Swagger2Markup.
  3. You should add Springfox only in testCompile and not in compile, because it removes many library dependencies and improves the start-up time of your application. Just add compile 'io.swagger:swagger-annotations:1.5.0' so that you can use the Swagger annotations. Have a look at the demo.

Some questions:

RobWin commented 8 years ago

One more finding: If you want to use Spring's io.spring.dependency-management Gradle plugin and the Spring IO Platform, you should also add

dependencyManagement {
    imports {
        mavenBom 'io.spring.platform:platform-bom:2.0.0.RELEASE'
    }
}
ashwanikumar04 commented 8 years ago

Did all the changes you mentioned. But still not working

Answers to questions:

  1. Nope, in the build folder asciidoc folder is created with 3 adoc files
  2. Yes, I copied the one from demo and placed at the same location. /src/docs

New gradle file

buildscript {
    ext {
        springBootVersion = '1.3.0.RELEASE'
        snippetsDir = file('build/generated-snippets')
    }
    ext['hibernate.version'] = '5.0.4.Final'
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
        classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10.1'
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.0.RELEASE'
        classpath 'io.github.robwin:swagger2markup-gradle-plugin:0.9.1'
        classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.asciidoctor.convert'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.github.robwin.swagger2markup'
jar {
    baseName = 'test'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
    maven { url 'https://repo.spring.io/snapshot' }
    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
    mavenLocal()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.security.oauth:spring-security-oauth2:2.0.7.RELEASE')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.postgresql:postgresql:9.4-1201-jdbc41')
    compile('javax.inject:javax.inject:1')
    //compile 'io.swagger:swagger-annotations:1.5.0'
    compile 'io.springfox:springfox-swagger2:2.3.0'
    compile("io.springfox:springfox-swagger-ui:2.1.1")
    compile('net.kencochrane.raven:raven-logback:6.0.0')
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.1")
    compile('org.projectlombok:lombok:1.12.6')
    compile('org.hibernate:hibernate-java8:5.0.4.Final')
    testCompile 'io.springfox:springfox-swagger2:2.3.0'
    testCompile 'org.springframework.boot:spring-boot-starter-test'
    testCompile 'io.springfox:springfox-staticdocs:2.2.3-SNAPSHOT'
    testCompile 'junit:junit'
    testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc'
    testCompile 'com.fasterxml.jackson.module:jackson-module-jsonSchema:2.4.0'
}
dependencyManagement {
    imports {
        mavenBom 'io.spring.platform:platform-bom:2.0.0.RELEASE'
    }
}
eclipse {
    classpath {
        containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
        containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.7'
}

ext {
    asciiDocOutputDir = file("${buildDir}/asciidoc")
    swaggerOutputDir = file("${buildDir}/swagger")
}

test {
    systemProperty 'io.springfox.staticdocs.outputDir', swaggerOutputDir
}

convertSwagger2markup {
    dependsOn test
    inputDir swaggerOutputDir
    pathsGroupedBy io.github.robwin.swagger2markup.GroupBy.TAGS
}

asciidoctor {
    dependsOn convertSwagger2markup
    sources {
        include 'index.adoc'
    }
    backends = ['html5', 'pdf']
    attributes = [
            doctype    : 'book',
            toc        : 'left',
            toclevels  : '3',
            numbered   : '',
            sectlinks  : '',
            sectanchors: '',
            hardbreaks : '',
            generated  : asciiDocOutputDir
    ]
}
RobWin commented 8 years ago

Can you share the project on GitHub?

ashwanikumar04 commented 8 years ago

Shared https://github.com/ashwanikumar04/spring-test

RobWin commented 8 years ago

Btw you starred this project and not https://github.com/Swagger2Markup/swagger2markup :)

ashwanikumar04 commented 8 years ago

Yep I did that :)

RobWin commented 8 years ago

thx :)

ashwanikumar04 commented 8 years ago

Any update on what is the problem :)

RobWin commented 8 years ago

Not yet. I can't run your project, because I dont have MongoDB installed.

RobWin commented 8 years ago

But I think your index.adoc file is missing in the folder /src/docs/asciidoc

ashwanikumar04 commented 8 years ago

Let me disable mongo db

ashwanikumar04 commented 8 years ago

It worked. Was missing index.doc on the proper location :+1:

RobWin commented 8 years ago

Nice! :dancers: