Gradle:多项目Gradle构建-在项目B编译期间调用项目A中找到的类的方法
我需要这样的建议,以解决以下多项目建成 在项目A中我有一个类用于创建web服务存根:Gradle:多项目Gradle构建-在项目B编译期间调用项目A中找到的类的方法,gradle,Gradle,我需要这样的建议,以解决以下多项目建成 在项目A中我有一个类用于创建web服务存根: /src/main/java/com/mycompany/generatewstubs.java 该类有一个方法: 公共静态void main(字符串[]args)引发异常 它连接到一些Web服务并基于它们生成java类 在项目B中我有一个类,它不需要项目a生成的类 /src/main/java/com/mycompany/Client.java 我的挑战是能够: 1) 在B之前编译A(简单) 2) 向项目B提
/src/main/java/com/mycompany/generatewstubs.java
该类有一个方法:
公共静态void main(字符串[]args)引发异常
它连接到一些Web服务并基于它们生成java类
在项目B中
我有一个类,它不需要项目a生成的类
/src/main/java/com/mycompany/Client.java
我的挑战是能够:
1) 在B之前编译A(简单)
2) 向项目B提供com.mycompany.generatewstubs.class(不知道如何)
3) 在项目B构建中,在解析B依赖项之前调用com.mycompany.GenerateWSStubs.main(“”)。(我知道怎么做,但不是在解决依赖关系之前)
这将把一些类输出到一个包com/mycompany/ws/。。。我只需要在编译之前将其提供给B
4) 编译并打包到jar,项目B包括两个:(不知道如何)
com/mycompany/ws/。。。(通过运行com.mycompany.generatewstubs.main(“”)生成的类)
com/mycompany/Client.class
到目前为止,我所尝试的:
A.gradle
apply plugin: 'java-library'
dependencies {
implementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.apache.axis2', name: 'axis2-adb-codegen', version: '1.7.6'
}
buildscript {
dependencies {
//the following seems working but is terrible way to specifying this inclusion, and the jar might not be there if I did a clean
classpath files("../A/build/libs/A.jar")
}
}
apply plugin: 'java-library'
dependencies {
implementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.apache.axis2', name: 'axis2-adb-codegen', version: '1.7.6'
// The following does not seems to allow adding com.mycompany.GenerateWSStubs to the compile path to allow me running main
compileClasspath project(':A')
}
compileJava {
// This should ensure that A.jar is built
dependsOn ':A:build'
doFirst {
def obj = new com.mycompany.GenerateWSStubs()
obj.main('someparameters')
}
}
B.gradle
apply plugin: 'java-library'
dependencies {
implementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.apache.axis2', name: 'axis2-adb-codegen', version: '1.7.6'
}
buildscript {
dependencies {
//the following seems working but is terrible way to specifying this inclusion, and the jar might not be there if I did a clean
classpath files("../A/build/libs/A.jar")
}
}
apply plugin: 'java-library'
dependencies {
implementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.apache.axis2', name: 'axis2-adb-codegen', version: '1.7.6'
// The following does not seems to allow adding com.mycompany.GenerateWSStubs to the compile path to allow me running main
compileClasspath project(':A')
}
compileJava {
// This should ensure that A.jar is built
dependsOn ':A:build'
doFirst {
def obj = new com.mycompany.GenerateWSStubs()
obj.main('someparameters')
}
}
问题:
1) 除非我使用buildscript def obj=new com.mycompany.generatewstubs()否则将失败。如何基于要在另一个项目中编译的类创建一个对象,而不象我那样静态地引用jar
2) main()接受几个参数,以了解如何读取某些URL以及存根类的存储位置
a) 我在gradle中使用什么变量来引用标准资源位置(src/main/resources)
b) 我应该在哪里输出com.mycompany.GenerateWSStubs.main()生成的类,以确保它们用于项目b中的依赖项并打包在b.jar中
非常感谢