asciidoctor-gradle-plugin icon indicating copy to clipboard operation
asciidoctor-gradle-plugin copied to clipboard

How to build files from different source files, located in different packages in sourcedir src/main/java?

Open pirancaci opened this issue 4 years ago • 9 comments

I'm working as a student software developer and my task is to provide a framework for building html and pdf files with gradle asciidoctor plugin from different asciidoc source files located in different packages in src/main/java. Say each package has one or more .adoc files inside, I want them to be converted to html and pdf ( which I already know how it works) and put them in different output directories in file system (refering to the packages they were part of). I have an issue with providing the possibility of building gradle with sourcedir in packages and another issue is the include directive, which is not working on files included on the same package as the source code. I would be very happy, if someone could give me a hint :D

The framework is supposed to work on big projects and to make the documentation easier for the programmers. I'm testing and practicing it now in a tiny project with 4 packages. Each packages has one class and one subpackage called docs. The docs subpackage includes one ascidoc file and one subpackage called images (refering to the imagedirectory). So I want to configure the asciidoctor task in the gradle build file in that way, so I can access all the asciidoc files from each package and put them in separated directories called lets say name_package1_docs, name_package2_docs ecc. And inside these folders should be the html and pdf folders respectively. My problem is I get an error when I try to build the gradle, because the asciidoc files are not located in the default sourcedir of the gradle asciidoctor plugin (src/docs/asciidoc), but in the src/main/java/package(package_name)/docs. I don't know how to solve this problem. I hope you have a good overview of what I'm trying to solve.

pirancaci avatar Mar 04 '20 13:03 pirancaci

Assuming your have src/main/java/foo/bar/a.adoc and src/main/java/alice/bob/b.adoc, then your starting point is

asciidoctor {
  sourceDir 'src/main/java'
}
asciidoctorPdf {
  sourceDir 'src/main/java'
}

which can build build/docs/asciidoc/foo/bar/a.html, build/docs/asciidoctor/alice/bob/b.html, build/docs/asciidoctorPdf/foo/bar/a.pdf etc.

I suspect that is not quite what you want though. I suspect you want something akin to alice.html, alice.pdf, foo.html, foo.pdf which will include all of the asciidoct file below src/main/java/alice and src/main/java/foo respectively?

If you can explain the last part in more detail, I might have a solution for you.

ysb33r avatar Mar 04 '20 14:03 ysb33r

Assuming your have src/main/java/foo/bar/a.adoc and src/main/java/alice/bob/b.adoc, then your starting point is

asciidoctor {
  sourceDir 'src/main/java'
}
asciidoctorPdf {
  sourceDir 'src/main/java'
}

which can build build/docs/asciidoc/foo/bar/a.html, build/docs/asciidoctor/alice/bob/b.html, build/docs/asciidoctorPdf/foo/bar/a.pdf etc.

I suspect that is not quite what you want though. I suspect you want something akin to alice.html, alice.pdf, foo.html, foo.pdf which will include all of the asciidoct file below src/main/java/alice and src/main/java/foo respectively?

If you can explain the last part in more detail, I might have a solution for you.

Hello, thank you so much for your comment. You really helped me to solve my problem. I got what I wanted. I was missing the line 'sourceDir 'src/main/java'. I have now another problem, which has to do with the include directive. Usually I use this directive which works fine when the asciidoc files are located in src/docs/asciidoc: include::{sourcedir}/example/example.java[] with sourcedir: ../../src/main/java

Now that I have asciidoc files located in src/main/java/package/docs the include directive is not working and gives me error message. I would be very thankful if you could help me with this issue as well.

This is the error message:

Multiple markers at this line

  • Validation failed:include::.. references not existing file:C:\Users\pcaci\Desktop\GenerateDoc\src\main\java\move\docs{sourcedir}\move\Move.java
  • include file not found: C:/Users/pcaci/Desktop/GenerateDoc/src/main/java/main/java/move/Move.java Untitled

pirancaci avatar Mar 04 '20 15:03 pirancaci

Is {sourcedir} defined as an attribute?

ysb33r avatar Mar 04 '20 16:03 ysb33r

yes it is defined as an attribute on the top of asciidoc file and in the asciidoctor task in the build.gradle file. 1

1

pirancaci avatar Mar 04 '20 16:03 pirancaci

This output :C:\Users\pcaci\Desktop\GenerateDoc\src\main\java\move\docs{sourcedir}\move\Move.java looks like {sourcedir} has the wrong value.

ysb33r avatar Mar 04 '20 16:03 ysb33r

This output :C:\Users\pcaci\Desktop\GenerateDoc\src\main\java\move\docs{sourcedir}\move\Move.java looks like {sourcedir} has the wrong value.

yes I understand it could be a problem with {sourcedir}, but I don't know why. Since I don't have much experience with sourceDir other than ../../main/java as in the gradle plugin examples. I discovered another issue, which is the images. They don't appear on the converted html file, only on the pdf file. I couldn't find a solution for that as well. I assume there is something wrong with the imagedir, but couldn't find out why. Maybe you have any idea? Thanks in advance

pirancaci avatar Mar 05 '20 13:03 pirancaci

Hello,

Please can you help me with this?

I don't know why the image is not appearing in html and the include directive is giving me error . Maybe you have a solution Please let me know :D I tried a lot, I don't what to do anymore.

Thank in advance

On Wed, 4 Mar 2020 at 17:56, Schalk W. Cronjé [email protected] wrote:

This output :C:\Users\pcaci\Desktop\GenerateDoc\src\main\java\move\docs{sourcedir}\move\Move.java looks like {sourcedir} has the wrong value.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/532?email_source=notifications&email_token=AIPQK47T7C7XOBQNEIMPQULRF2B3TA5CNFSM4LBHPZ6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENY4NQI#issuecomment-594659009, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIPQK46SEGTK3OJXTYFGO3TRF2B3TANCNFSM4LBHPZ6A .

pirancaci avatar Mar 06 '20 10:03 pirancaci

There are a number of issues in your build.

  1. You should use the asciidoctorPdf task for PDF generation.
  2. You should use the resources { include 'path/to/images/**' } block to point to your image location.

Also temporarily do

asciidoctor {
  doFirst {
    println "******* ${sourceSets.main.java.srcDirs[0]}"
  }
}

This might help you diagnose why your source directory is not correct.

ysb33r avatar Mar 10 '20 11:03 ysb33r

It would be best to continue these types of discussions in the project chat. I recommend closing this issue and picking it back up there if there's still more to discuss.

mojavelinux avatar Sep 23 '23 00:09 mojavelinux