我正在尝试构建一个java库(streaming-client.jar
)并在客户端微服务中使用它。
在这个 jar 文件中,我有一个 POJO 类,它扩展了第三方 POJO 类
@ConditionalOnClass({Options.class})
@ConfigurationProperties(prefix = "nats.spring")
public class ServerProps extends NatsProperties {
public ServerProps(){ super(); }
}
现在这个NatsProperties
类来自第三方库,该类扩展了另一个自动配置类。
当我使用ServerProps
在这个库本地,我可以访问以下方法NatsProperties
超级一流。
但是当我将此库导出为 jar 文件时。并在客户端应用程序中使用它。
NatsProperties
方法无法通过ServerProps
class
在客户处
ServerProps props = new ServerProps();
props.server("sdfsfsdfsdf")//server method cant be resolved,
EDIT
我尝试添加所有方法NatsProperties
类到我的自定义类StreamingServerProperties
然后当我尝试在其他项目中访问它们时,如下所示
StreamingServerProperties props = new StreamingServerProperties();
props.server("serverUrl") //Intellij complains that Cannot access io.nats.spring.boot.autoconfigure.NatsProperties
Streaming-client.jar 的 build.gradle
plugins {
id 'java-library'
id 'maven-publish'
id "com.github.johnrengelman.shadow" version "7.1.2"
}
group = 'com.dexter'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
}
tasks.named('compileJava') {
inputs.files(tasks.named('processResources'))
}
dependencies {
implementation 'io.nats:nats-spring:0.5.6'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.3'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
testImplementation 'org.junit.platform:junit-platform-engine:1.9.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
implementation('np.com.madanpokharel.embed:nats-embedded:2.1.0')
}
tasks.named('test') {
useJUnitPlatform()
}
我在用./gradlew build
生成一个 jar 的任务,并且使用这个 jar 我无法获得NatsProperties
类方法。
但如果我使用fatJar
任务由此shadow
插件我能够获取方法,但问题是它创建了所有库并且大小太大。