Add generated class files from another plugin into a separate Jar

Hello,

Plugin I am using generated class files that then I use in my project. What I would like to do though is to take these generated classes and package them into a Jar for distribution. So other projects don’t need to go through the same process of generating these class files.

What I tried is:

tasks.register('classJar', Jar) {
  dependsOn tasks.assemble
  doLast {
    from layout.buildDirectory.dir("classes/java/main/api/trc/").collect {
      zipTree(it)
    }
  }
}

But it doesn’t work, am I totally on the wrong track or there is just a minor mistake here?

Tried also this:

FileFilter fileFilter = new FileFilter() {
  @Override
  boolean accept(File pathname) {
    return pathname.isFile()
  }
}

archiveFileName = "myCustom.jar"
from file("$buildDir/classes/java/main/api/trc/").listFiles(fileFilter).sort().collect() {
  zipTree(it)
}

Above, I am not entirely sure how to assign this archiveFileName to the actual Jar I Want to make, found this in some example that in the meantime I can’t find anymore…

Also tried this:

archiveBaseName.set('grpc-client-lib')
archiveFileName.set('grpc-client-lib.jar')
archiveVersion.set('1.0')
destinationDirectory.set(file("$buildDir/libs"))

include '**/*.class'

// Include the dependencies in the JAR file
from {
  configurations.runtimeClasspath.collect {
    it.isDirectory() ? it : zipTree(it)
  }
}

But still I am getting no jar file. When I print out the files in the directory I am wanting to zip it shows files that I expect. Not sure where else to look for an error?