Reputation: 1313
Since the Maven tool does not automatically exclude transitive dependencies at binary-compile-time + publishing
and neither does Gradle, I understand the need to divide between "core" and "dependent" submodules.
Artifact (io.github.org.artifact)
│
├── build.gradle
├── settings.gradle
├── gradle.properties
├── Core (io.github.org.artifact-core)
│ └── build.gradle
└── Dependent (io.github.org.artifact-dependent)
└── build.gradle
The issue is that... (from what I've heard... and even as a personal conclusion based on the evidence and practices across the board... ) it would be perfectly reasonable to ALSO publish the "whole" as a single artifact.
dependencies {
implementation('io.github.org:artifact:1.0.5')
}
But also...
dependencies {
implementation('io.github.org:artifact-core:1.0.2')
implementation('io.github.org:artifact-dependent:1.0.3')
}
(
Assume dependent
as a module that implements other dependencies, and core
as an artifact that DOESN'T.
In this case, artifact
is used as a grouping device, facilitating the implementation of both under a single coordinate reference.
)
In reality these are 3 different artifacts, but keep in mind that core
and dependent
where already 2 separate artifacts in Maven Central's eyes, and their apparent relationship was just merely defined by naming convention ALONE (The "-" between "artifact" and "core" in this example), I see no issue on publishing "the whole" artifact as a single unit.
As far as I know, doing this via the parent's publish
task in its own build.gradle
file, will trigger both submodule's own publish task... ... ... end of story.
It seems defining the parent's settings.gradle
as:
rootProject.name = 'artifact'
include 'artifact-core'
include 'artifact-dependent'
...will just make the parent's build.gradle
aware that calling \gradlew publish
on the parent should call each submodule's publish
task independently, but NOT publishing the whole project as a whole.
The main idea is to have an artifact as if the project structure was:
Artifact (io.github.org.artifact)
│
├── build.gradle
├── settings.gradle
├── gradle.properties
└── src
└── main
└── java
├── core
└── dependent
In the end, the branching is not too important since Maven seems to remove everything between /src/
to /java/
so that imports look like artifact.core.SomeClass
The ideal would be for a build.gradle
that, upon calling publish
would upload 3 artifacts of coordinates:
io.github.org:artifact-core:1.0.0
io.github.org:artifact-dependent:1.0.0
io.github.org:artifact:1.0.0
Is this possible to do via parent build.gradle
(aka. using the same project directory structure)? or should I create 3 submodules with their own build.gradle
each and the third branch being simply a copy-paste of the other 2 contents into a single branch?
Upvotes: 1
Views: 55
Reputation: 2438
The default behaviour is to publish the 3 jars - each only containing their respective sources.
It appears that when you state - "whole" so as to use only a single dependency, you actually want a Uber Jar (a single jar with code from all modules).
you can do that by creating an additional jar task that can combine the 3 modules in the root project (archive) - say with name artefact-all or using classification all
refer https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_example
Upvotes: 1