Rocking the gradle

fronobulax

Developer
Staff member
I will add my questions and lessons here in hopes that some answers will be easier to find when other documentation and instructions are updated.

Kolmafia is phasing out Ant and replacing it with Gradle.

To use Gradle your system will need a command line git client, an installed version of Java 9 or better and a git clone of the KoLmafia repository from GitHub.

gradle is usually invoked from a command line, followed by a list of parameters or targets. Windows users should invoke gradlew.bat and users of other systems should try gradlew. Things are simplest if these are invoked from the top level directory of the local repository. gradle should probably not be separately installed on a system if it is only needed for KoLmafia. There are some versioning incompatibilities and the wrappers will just use Java to run the right version.

The target, shadowjar will compile and build a KoLmafia jar from the local repository. At present (and unlike Ant daily) it does not pull the latest code from GitHub first. It will delete KoLmafia*.jar from the dist directory and create KoLmafia-abcde.jar where "abcde" is a revision number. If it is not a five digit number in the built jar name then there is probably a problem with something local, with Java being older than version 9 the prime suspect.

Targets to run tests, generate coverage metrics and update the local repository are under development (but not be me). There are likely to be targets that combine one or more of these tasks as well.
 

fronobulax

Developer
Staff member
gradle generates a lot of output, much of which disappears if the command console is closed. Sometimes the output is interesting or caused by errors. gradle seems to have the capability to save console output to a file but I haven't figured out how to do that yet. Any help?

My ideal would be to have gradle unconditionally generate a console log every time it is run. The file would be in the same directory as gradle is being run from. It would have the same name each time so that old logs would be overwritten and git could be told to ignore it.
 

fronobulax

Developer
Staff member
Are we able generate coverage metrics locally? If so, which task and where will the output be?

Can we run the security scanning tests locally? If so, which task and where will the output be?
 

heeheehee

Developer
Staff member
Bash:
$ ./gradlew jacocoTestReport
$ ls build/reports/jacoco/test/html/index.html
as your entry point.

I don't know how the security scanning thingy is set up. Is that a github action?
 

heeheehee

Developer
Staff member
Signs point to "yes".

As far as I can tell, we can't run that specific tool locally.

There are a number of other static analysis tools we could run, though. PMD seems to be a popular one that is directly integrated with Gradle. (I tried adding it, and then noted there were 400+ findings. I'll see how long it takes me to work through those...)

edit: that 400+? apparently just for lib/... I think there's no way we deal with all of these at once.
 
Last edited:

MCroft

Developer
Staff member
I will add my questions and lessons here in hopes that some answers will be easier to find when other documentation and instructions are updated.

Kolmafia is phasing out Ant and replacing it with Gradle.

To use Gradle your system will need a command line git client, an installed version of Java 9 or better and a git clone of the KoLmafia repository from GitHub.
I think we removed the git cLI requirement, or we are about to do so.
 

heeheehee

Developer
Staff member
Well. You need to be able to get a local git repo, somehow. But MCroft is correct in that you should no longer need the git CLI tool in order to run any of the gradle tasks.
 

fronobulax

Developer
Staff member
I recall that the git command line requirement was being removed but I have done nothing to confirm it.

My recollection of the motivation was to do some kind of automatic update. That is probably worth discussing because I have seen gradle give me different results depending upon whether I last viewed main or a local branch. I know what I want when there are zero or one local branches but I am not sure what to ask for when multiple branches exist.

When I installed my git command line client I was explicitly asked to choose options related to EOL. I don't think that matters anymore since my tools seem to tolerate either flavor and spotlessApply will address that, right? Exception might be data files but I think we are squashing them as they are observed.

I'll try the coverage report.

Is there a capability to alias gradle tasks? "muscle memory" would prefer gradle daily to gradle shadowjar and gradle coverage or clover to jacocoTestReport which I really want to associate with Jaco Pastorius.

I can do this with batch files or OS level aliases but I have fallen into the habit of opening a command line and typing so...
 

fronobulax

Developer
Staff member
Well I miss the Clover html format because it made it easy for me to select target projects but I can work with jacoco. Thanks.

New tip - gradle tasks answers a lot of the questions I have posted here. I should learn to try it and then post :)
 

MCroft

Developer
Staff member
Is there a capability to alias gradle tasks? "muscle memory" would prefer gradle daily to gradle shadowjar and gradle coverage or clover to jacocoTestReport which I really want to associate with Jaco Pastorius.
➕1️⃣ for Jaco Pastorius.

We can (haven't tested it) put in a task that is noting but 'dependsOn' tasks.

Rich (BB code):
task JacoPastorius {
    dependsOn BassOfDoom
    dependsOn WordOfMouth
}

But ./gradlew shadowJar isn't ant daily.

The ant daily task ran svn update before building. You may need a bunch of git commands in a task, and then make daily depend on the tasks gitUpdate (stash/pull/stash pop) and then shadowJar (or runShadow).
 

fronobulax

Developer
Staff member
I have replaced ant daily in my workflow with manually updating one or more local branches and then running shadowJar. I don't care what else shadowjar does as long as it builds a jar from what is on my disk when it is invoked. My experience with tools and branches suggests it would be difficult to actually script a gradle daily equivalent in the presence of more than one branch or with names that don't follow a convention. Intellectually it can be done but I'm not yet prepared to learn enough gradle and git to figure out how and I accept that there are other things the people who might know be doing that would help more people.
 
Top