Remember the Maven site plugin? The one that used to look like this but now looks nice like this?
Yeah I do too, and I miss it. Gradle really doesn't provide anything like this. Good news! There are so many people that attempted it. Bad news! Most of them failed attempts and are dead and abandoned.
So I took a stab at it and borrowed from some of the half working projects and heavily from maven, bootstrap, the work of others, bookies, loan sharks, thieves and the Elders of Canterbury, simplifying things where ever possible.
Well it's not exactly the Maven Site Plugin, but it's our version of it. It's pretty darn close. It uses theming inspired by Apache Fluido and is loosely based on the work Paul Speed-2 @ filament did over here.
Instead of the APT based sites, we opted for a simpler solution, a singular page template which is then merged with generated content and your content using Markdown and the Common Mark renderer. We also looked at Pegdown but ran into performance issues. Asciidoc/docbook
The Site Plugin (and sorry for stealing, I mean borrowing, err.. leveraging the name) uses a basic template file to produce the majority of the content. The template is then populated by a number of environment variables, the gradle.properties file, the dynamic menu generation, and finally, the content.
The content comes from internally generated content that is generally useful to developers (all the good old Project Information stuff that Maven's plugin does), and from the stuff you provide in the form of Markdown or Asciidoc.
Note: as of 1.0.14 this isn't necessary. The site plugin will auto download what you need. But if you're disconnected from the internet on the first run, it will probably fail. In which case, you should follow this procedure or clone gradle fury and host it in your environment.
1 .In the root of your project make the following directory structure
src
src/site
src/site/index.md
2 .Next you'll want to grab all the junk that's in Gradle-Fury's src/site
folder. You really just need the img
,css
, and js
folders.
index.md
It is required! This is your splash page for your project. Make a good first impression!
Note: if you're looking for gradle-fury's index.md page, you won't find it. Instead, we copy this readme.md to the right place and rename it.
4. In your root build.gradle
adding the following
apply from 'https://raw.githubusercontent.com/gradle-fury/gradle-fury/master/gradle/site.gradle'
Build your project normally. We suggest running all possible tasks that generate reports, such as connectedCheck
or if you are you using the Quality Plugin just call build
.
Build the site with gradlew site
. The output normally goes to root/build/site
. The output location can be overridden by putting this in the root build.gradle file
ext.buildWebsiteDir = rootDir.absolutePath + "/docs/"
The Site plugin only requires that you have a gradle.properties
present and populated with the pom settings. These are used to generate a number of the pages, such as licenses, name, description, urls, issue trackers, etc
Simply place any custom HTML, Markdown, Asciidoc or PDF docs in the src/site
and they will be included in the site build and linked in the left hand side nav menu.
Gradle-Fury's site's plugin can also use Github styled Markdown and Asciidoc formatted docs. These docs are rendered down to HTML and injected into the same template as the rest of the site.
Most Github flavored markdown tags are supported. You can also any files put in src/site/
will
be included in the site. Any html or pdf files in the root src/site/
will be auto-linked on the left hand site
navigation menu. We also have some magic to resolve relative links from markdown to markdown pages, but only if the article link doesn't have any spaces in it.
Replace the img/logo.png
with whatever you want.
Well, you have direct access to modify the template. Do whatever you want!
./gradlew install -Pprofile=ci
# if needed, for distribution projects
./gradlew distZip -Pprofile=ci
# if needed, for on device android test and reports
./gradlew cC
# finally, generate the site
./gradlew site -Pprofile=ci
The output goes to rootDir/build/site/
Here's a quick list
If you're really bored, continue to the next section. This bit is all about what I found difficult with this task.
Task order is a challenge - figuring out in what order to scan for stuff, generate content and populate content was tricky to get right. I finally ended up with a working solution that performs the following
Regarding the dumb part, gradle as 0 governance on build reports. As such, I had to write a lot of stupid fragile code that's plugin specific and java vs android specific, and android normal vs android with flavors/variants. The folder structures are inconsistent and there's no naming conventions for anything. I hate it.
This part has to be done with Maven since gradle's caches are not portable.
Make a pom.xml
and then copy and paste the maven composite dependency data in that the site generates. Then run maven
mvn dependency:go-offline dependency:sources dependency:resolve -Dclassifier=javadoc
It may fail for android specific libraries that are included with the SDK. Manually remove those dependencies from the pom and retry until you get everything.