Gradle 7.0 - put output jar from one submodule into another

I have Gradle 7 project & java 16, there are two sub modules

 - Root
   - sub project A
   - sub project B

My goal is following:

1) When project A is build it creates a A.jar file.
2) When project B is build it creates a B.jar file that contains an unexploded A.jar output from build of project A

To be more clear B.jar should look something like this

\META-INF
\my
  \package
    \tree
      SomeClassInsideBJar.class
\A.jar
URI aJarUri = someClassInsideBjar.getClassLaoder().getResource("A.jar");

Subproject A build just fine, but i cannot figure out how to embed its output jar into B.jar

Please not that i do NOT want to add project A as dependency to project B. This is due to nature of project im working on. project B is a bootstrap for project A, but i do not want to bother you with details.

in a nutshell i do not want this in project B

dependencies{
   compile (':A')
}

I’m going to assume that means you don’t want a compile/runtime dependency but that different kinds of dependencies are allowed.

In B:

configurations {
    embeddedJars
}
dependencies {
    embeddedJars project( ':A' )
}
jar {
    from( configurations.embeddedJars )
}

Note: this will also include transitive dependencies on A’s runtimeClasspath.

This solution has drawbacks, like it was mentioned - transitive dependencies are inside the jar. As well classes are not available for the compilation with this configuration

I posted here a way how to do this java - Put jar output from one module into another - Stack Overflow

Your SO answer is actually pretty bad and also does not answer the question here.
The question here is, how to inlcude the jar as a whole, not the contents.
If the transitive libs are not wanted, one can simply declare the dependency or configuration as non-transitive.
On the compile classpath they are most probably not needed for the use-case here and if, then the dependency can simply declared on compileOnly or whereever needed.

Your SO answer also directly accesses the source set output of a different project which is very bad and unsafe and shouldn’t be done. If you need outputs of another project, you should use the proper cross-project publishing documented at Sharing outputs between projects.

Thank you for the explanation