Hello,
I need so suggestions to solve the following multi project built
In project A I have a class of this kind used create web service stubs:
/src/main/java/com/mycompany/GenerateWSStubs.java
The class has a method:
public static void main(String[] args) throws Exception
that connects to some webservices and generate java classes based on them
In project B
I have a class than needs the classes generated by project A
/src/main/java/com/mycompany/Client.java
My challenge is to be able to:
- Compile A before B (easy)
- Make available com.mycompany.GenerateWSStubs.class to project B (don’t know how)
- From project B build, invoke com.mycompany.GenerateWSStubs.main(’’) before B dependencies are resolved. (I know how to do it, but not before dependencies are resolved)
This will output some classes to a package com/mycompany/ws/… I just need to make this availble to B before compile - Compile and package to jar, project B including both: (don’t know how)
com/mycompany/ws/… (the class generated by running com.mycompany.GenerateWSStubs.main(’’))
com/mycompany/Client.class
What I have tried so far:
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'
}
B.gradle
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')
}
}
Questions:
- Unless I use buildscript def obj = new com.mycompany.GenerateWSStubs() fails. How can I create an object based on a class to be compiled in another project without statically referring to the jar as I did?
- com.mycompany.GenerateWSStubs.main() accept several parameter to know how to read some URL and where to store the stub classes.
a) What variable to I use in gradle to refer to standard resources location (src/main/resources)
b) where should I output my classes generated by com.mycompany.GenerateWSStubs.main() to be sure that they are used for dependencies in project B and packed in B.jar?
Thank a lot