4

Introduction

I am currently working on a GitHub action that generates a JavaDoc and publish-it to GitHub, without need to configure JavaDoc inside the project.

Affected code:

mvn org.apache.maven.plugins:maven-javadoc-plugin:3.3.1:aggregate

Problematic

The problem with this code is that does not work with Gradle project

Question

And I was wondering if it would be possible to be able to do the same with Gradle? ie to be able to use the JavaDoc generation without it being in the project configs.

ThrowsError
  • 1,169
  • 1
  • 11
  • 43
  • Why do you wish to avoid modifying the build script and committing the changes? That seems like the easiest approach. – Slaw Jun 18 '22 at 00:33

2 Answers2

1

I don't know what your project structure is, but in a default gradle project you should be able to generate Javadoc just with a gradle javadoc command without any changes to your project. The only requirement is that the java plugin is used.

All the other configurations described by @VonC are only needed if you want to select only specific files or if your project is not structured in a standard way.

Just try running gradle javadoc and look for the generated doc in build/docs/javadoc/ folder

3Fish
  • 640
  • 3
  • 18
0

Check first if org.gradle.api.tasks.javadoc.Javadoc could help:

As mentioned here, that would be:

apply plugin: 'java'

task myJavadocs(type: Javadoc) {
  source = sourceSets.main.allJava
}

Example (for publishing to Bintray, which was since sunset): gradle-example/build.gradle.

You can integrate that with a GitHub Action building with Gradle.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your answer! But your solution needs to have a JavaDoc plugin inside your Gradle configuration. Unfortunately, I search to use JavaDoc generation without touch project configuration. – ThrowsError Jun 17 '22 at 17:50
  • 1
    @ThrowsError But if this is a GitHub Actions, it starts with a checkout of the repository. Which means, once checked out, you can modify the project configuration, and build it with that new capability. – VonC Jun 17 '22 at 19:13
  • Indeed, do you have an example to dynamically add a Gradle plugin with GitHub action? – ThrowsError Jun 18 '22 at 00:10
  • @ThrowsError I mean, that would be some `run:` script shell commands to modify the file, a bit like in https://github.community/t/github-actions-to-make-changes-to-a-file/132819/2 (except you don't have to add/commit and push those changes). – VonC Jun 18 '22 at 00:13