Example of apiElements and runtimeElements with java-library

I’m trying to understand the java-library plugin.

I get the gist of using the api and implementation for dependencies.

But what would be an use case for runtimeElements or apiElements?

The reason for that is I’m trying to compile a sample project and getting class not found error with all dependencies declared as api.


apiElements and runtimeElements are not important for end users, they are mostly there for plugin authors to wire in custom Configurations.

Can you please provide a reproducible sample, so we can see what problem you are facing?

Hi @st_oehme - though it doesn’t answer this question I too am curious to see apiElements and runtimeElements used “in the wild”. Can please you post a real-world example?

Yes, the official doc is too vague to understand the meanings of apiElements, runtimeElements, compileClasspath, etc. Wish there would be some concrete examples!

I second that. How do I resolve the artifacts required to run module?

I am attempting to build a zip file that contains all the runtime jars required to execute a module. I used to use the runtime configuration, prior to moving to java lib plugin. Now it looks like I need to use runtimeElements but it says I cannot access this directly. Can you provide a method to resolve the artifacts from this configuration?

What went wrong:
Could not determine the dependencies of task ‘:moda:distZip’.

Resolving configuration ‘runtimeElements’ directly is not allowed

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

WHERE the code has something like this

task modAZip(type: Zip) {
baseName += ‘-dist’
into(‘moda/lib’) {
//from configurations.runtime //this used to work
from configurations.runtimeElements //thought I was allowed to use this but no
from jar

1 Like

apologies the zip task name is correct I just sanitized it for the forum