I'm working on a framework which has several consu...
# community-support
s
I'm working on a framework which has several consumers. Framework's dependencies are not getting added to consumer's classpath. Below are details..
Framework side: ----------------- I have framework (my-framework) with few modules (api, inbound, outbound) and published
my-framework-root-bom
which includes (
api,inbound,outbound)
along with
my-framework-platform-bom
(which has framework's dependencies) and in each subproject i'm including
implementation platform(project(':platform'))
to resolve dependencies for subproject. I defined pre-compiled script plugin under
buildSrc/framework-deps.gradle
to include all common stuff used by subprojects. Below are details of these configurations:
Copy code
root project's settings.gradle
---------------
rootProject.name = 'my-framework'
include 'platform'
include 'my-api'
include 'my-inbound'
include 'my-outbound'
Copy code
platform's build.gradle which publishes platformBOM:
-------------------------------------------

plugins {
    id 'java-platform'
	id 'maven-publish'
}

dependencies {
	constraints {
		
		/* THIRDPARTY DEPENDENCIES */
    	api "org.springframework:spring-core:5.3.22"
    	api "org.springframework:spring-beans:5.3.22"
		api "org.springframework:spring-context:5.3.22"
		
		api 'jakarta.servlet:jakarta.servlet-api:4.0.4'
		api 'jakarta.validation:jakarta.validation-api:2.0.2'
		api 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
		api 'jakarta.jws:jakarta.jws-api:2.1.0'
		api 'jakarta.xml.ws:jakarta.xml.ws-api:2.3.3'
        api 'org.slf4j:slf4j-api:1.7.36'
		
		etc
}
Copy code
buildSrc/framework-deps.gradle
------------------------------

plugins {
    id 'java-library'
    id 'maven-publish'
}

dependencies {
    
    implementation platform(project(':platform'))
    
    implementation 'org.apache.logging.log4j:log4j-core'
    implementation 'org.apache.logging.log4j:log4j-api'
    implementation 'org.slf4j:slf4j-api'
    
    etc

 /*   implementation 'jakarta.jws:jakarta.jws-api'
    implementation 'jakarta.ws.rs:jakarta.ws.rs-api'
    implementation 'jakarta.validation:jakarta.validation-api'*/

    api 'jakarta.validation:jakarta.validation-api'
    api 'jakarta.ws.rs:jakarta.ws.rs-api'
    api 'jakarta.jws:jakarta.jws-api'
	
}

//If i add jakarta libs under implementation, its showing under runtimeClaspath at consumer side. So i changed to "api". Now i see POM file updated as scope "compile" but still no luck at consumer side..
and this plugin is included in all my subprojects like this ie., `inbound's build.gradle`:
Copy code
plugins {
    id 'framework-deps'
}

dependencies {
	implementation project(":my-api") 
//and other deps inherited pre-compiled script plugin..
}
With this setup, framework's build successful and root BOM, platform BOM everything is published to artifactory.. i see platform's POM has dependencies with versions .. subproject's POM has reference to platform's POM..
Consumer side: -----------------
Copy code
dependencies {

    implementation platform('mygroup:my-framework-root-bom:1.0.0')

    implementation 'mygroup:my-api'
	implementation 'mygroup:my-inbound'
	
    //implementation 'jakarta.jws:jakarta.jws-api:2.1.0'
    //implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
	
}
Consumer defines one webservice which has classes from
jakarta
libs. But i already defined
jakarta
libs as dependencies to
my-inbound
module. But those are not getting added to consumer module's classpath. i see all those dependencies are downloaded at consumer side... But Its expecting to define those libs along with versions again. I'm not sure why...
can someone please share inputs.. i'm not sure whether this is expected behavior or not..
This is what i observed. If i define version again in pre-compiled script plugin,
buildSrc/framework-deps.gradle
, like this:
Copy code
/*api 'jakarta.jws:jakarta.jws-api'
api 'jakarta.ws.rs:jakarta.ws.rs-api'
api 'jakarta.validation:jakarta.validation-api'*/

api 'jakarta.validation:jakarta.validation-api:2.0.2'
api 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
api 'jakarta.jws:jakarta.jws-api:2.1.0'
api 'org.slf4j:slf4j-api'
these are getting added to consumer classpath. For example, i didn't define version for
slf4j-api
at consumer side, its throwing error during build:
Copy code
* What went wrong:
Execution failed for task ':consumer-inbound-api:compileJava'.
> Could not resolve all files for configuration ':consumer-inbound-api:compileClasspath'.
   > Could not find org.slf4j:slf4j-api:.
     Required by:
         project :consumer-inbound-api > mygroup:my-framework:1.0.0
         project :consumer-inbound-api > mygroup:my-inbound:1.0.0

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':consumer-outbound-adapter:compileJava'.
> Could not resolve all files for configuration ':consumer-outbound-adapter:compileClasspath'.
   > Could not find org.slf4j:slf4j-api:.
     Required by:
         project :consumer-outbound-adapter > mygroup:my-framework:1.0.0
         project :consumer-outbound-adapter > mygroup:my-outbound:1.0.0
If i define version for
slf4j-api
in
framework-deps.gradle
, consumer build works. But why is it required, because in
framework-deps.gradle
, i'm already including platform BOM and framework build itself successful without specifying versions but its failing only at consumer if i dont specify versions again
framework-deps.gradle