I have been trying to find a way I can install custom jars into the local maven repo with gradle. Basic I have a list of jar files I want to install with an artifact id, group id and version.
Most of the examples I found assumes gradle is building the artifacts, but in my case I download the files and now want to add them to the local maven repo
Take a look at Publishing Multiple Modules to Maven with the maven-publish plugin. You’ll often see the from components.java, which requires a SoftwareComponent. However, you can also use an artifact. The example directly references the output of a task, but a file(...) will work just fine too. You could list out each artifact like this:
However, if you have your list in a parseable format with the group, artifact, version, and file name, you could easily loop through that to create each MavenPublication. Alternatively, if all necessary, unique information is embedded in the file names, just looping through all the files in the folder would be fine too. You can then handle publishing of them at once with the publishToMavenLocal task.
I got so far I was able to create the Maven Publication list from a list of files with the code below and it works fine with the publishToMavenLocal as long the files exist in the configuration phase.
But in my case I download a zip file and unpack it and then scan the files, how can I lazy initializing the Maven Publication list and make it work with publishToMavenLocal?
With your current code, I would expect that the publishing extension isn’t being configured soon enough. The plugin can handle creation of publications in the executing phase, just not if it already is getting ready to publish and there isn’t anything to publish yet. The bootstrap task depending on all of the other tasks with mustRunAfter ordering doesn’t model the dependencies accurately enough. This should work correctly if you model the true dependencies of each task.