Setting target directory for gRPC classes generated by Quarkus Gradle plugin - gradle

Running ./gradlew quarkusGenerateCode works well, however the generated sources fall under the build directory:
I wouldn't like to set this path as a Gradle SourcesSet, "Mark Directory As" Generated Sources Root in Intellij, and so on as it's under the build directory.
Is there a way to set the output dir to something such as src/quarkus-generated-sources? The Quarkus user guides and the gradle plugin documentation are not too informative regarding that subject.
There's the build.gradle, nothing much special about it
plugins {
id 'io.quarkus'
}
dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-grpc'
...
}

There is no way to specify an alternative path for the built-in code generation mechanism.
The classes generated by Quarkus from your *.proto files may change quite often. If you run Quarkus in the development mode, they will be regenerated on each change (in the *.proto files). In such a set up this is an outcome of the build rather than a source, that's why I put it in build.
I think you could use Gradle protobuf plugin to generate the java files. It has an option to specify the output directory. Don't forget to register quarkus-grpc-protoc-plugin similarly to Maven protobuf plugin configuration.
The drawback of switching to it is that you won't be able to use the full power of the development mode when modifying the *.proto files.

Related

Building open source dependencies using gradle

I really don't have much experience in developing let alone using build tools.
I was assigned a task to build dependencies locally and get the jar files.
say I have a list of deps (GAV) like this:-
1. org.jetbrains.kotlin:kotlin-stdlib:1.6.0-RC
2. com.auth0:java-jwt:3.18.2, etc
3. openapi4j:openapi-operation-validator:1.0.7, etc
So i was able to download the source code url from maven repository and source code from github programmatically, for example :-
org.jetbrains.kotlin:kotlin-stdlib:1.6.0-RC - https://github.com/JetBrains/kotlin
com.auth0:java-jwt:3.18.2 - https://github.com/auth0/java-jwt
openapi4j-openapi-operation-validator-1.0.7 https://github.com/openapi4j/openapi4j
but there are many build.gradle files in different directories, how do I know which directory should I move into before running the gradle build command.
Things I have already tried and failed:-
For deps like this openapi4j:openapi-operation-validator:1.0.7, i can directly go into the openapi-operation-validator folder in the Github repo (https://github.com/openapi4j/openapi4j ) and run the gradle build command, but not all projects are structured like that I guess?
For deps like this com.auth0:java-jwt:3.18.2, the artifactId (java-jwt
) is already present in the github path (https://github.com/auth0/java-jwt), so i can run the gradle build command on the root github repo.
From the spring guides , among all the Gradle.build files available I can check which file has:-
jar {
archiveBaseName = <artifactId>
archiveVersion = <version>
}
, then I can move to that dir and run Gradle build, but not all build.gradle files have this.
None of the above approaches are concrete, is there any other firm approach that I can use to tackle the problem?
Your approach is generally correct.
You need to find the source code in github/gitlab/wherever, read the readme file and try to build it with whatever build tool was used there.
This may or may not work.

How Do You Specify Where The Gradle Wrapper Installs Gradle?

I have an off the shelf application that ships a version of gradle with it. It also has scripts that are hard coded to set GRADLE_HOME to this location.
I want to zip up this dir, put it in nexus and replace it with the gradle wrapper.
How do I configure the gradle wrapper to download this zip from nexus and extract it to a specific location in the project?
EDIT: In the gradle-wrapper.properties I have
distributionPath=wrapper/gradle
However, I end up with it being unzipped to
...\wrapper\gradle\gradle-2.3-bin\8gn7esgljqyucijpbynjk93oc\gradle-2.3
How do I get it to unzip to the path I specified and not to the subdirs?
The location to which Gradle gets unpacked is a combination of the distributionBase and distributionPath properties in gradle-wrapper.properties file. The location specified by distributionPath will always be considered as relative to distributionBase. The only available values for distributionPath are GRADLE_USER_HOME and PROJECT. Even when using PROJECT the wrapper will still generate the folder structure you see above.
If you want to control this more precisely I'd suggest not relying on the wrapper to do this and instead add a task to your build specifically for this purpose.

How to utilize buildSrc directory with gradle?

In the gradle documentation says:
Builds which utilize a buildSrc directory will generate a second
profile report for buildSrc in the buildSrc/build directory.
How can we do that (utilize build/Src) via the gradle sript, couldn't you help me?
You may put your helper scripts/classes to various places. One of them is buildSrc directory.
See below quote from gradle documentation.
When you run Gradle, it checks for the existence of a directory called
buildSrc. Gradle then automatically compiles and tests this code and
puts it in the classpath of your build script. You don't need to
provide any further instruction. This can be a good place to add your
custom tasks and plugins.
Your qoute only tells that if you use buildSrc directory, you will have second profile report.

How to load a specific build.gradle/gradle.properties for default build process

I have three build.gradle with different name under the same directory
dev.build.gradle
uat.build.gradle
prd.build.gradle
I have 4 issues
"gradle build" will just use build.gradle only to start the java plugin build task, but "gradle -b dev.build.gradle" will not start the java plugin build task
gradle --help seems not having an option to load a specific gradle.properties. There is another way that creating three directories(dev, uat, prd) under the project root and putting a responding build.gradle version in it. finally, start the java plugin build process. I dont like this because I just want build.gradle or gradle.properties files in the same directory
how to copy files in gradle without explicitly specify task name in the command line(gradle build copy).
ad 1. The correct command is gradle -b dev.build.gradle build.
ad 2. If you want to use properties files other than build.gradle, you'll have to do it on your own (e.g. using the java.util.Properties class). There is also a third-party properties plugin.
ad 3. This doesn't seem to be a question.
ad 4. You should turn this into a separate question.

bndtools Activator bundle

How can I create a simple bundle with an Activator in bndtools?
It keeps saying that:
The JAR is empty: The instructions for the JAR named com.myproj did not cause any content to be included, this is likely wrong bnd.bnd /com.myproj Unknown Bndtools Problem Marker
Unused Private-Package instructions, no such package(s) on the class path: [com.myproj] bnd.bnd /com.myproj Unknown Bndtools Problem Marker
The way I create this project in Eclipse is:
Create new "Bndtools OSGi project"
Right click, configure - Convert to Maven project
Create Activator.java in package com.myproj.
Add com.myproj to private packages
Set activator to com.Activator
Here is my bnd file:
Bundle-Activator: com.myproj.Activator
Private-Package: com.myproj
My generated jar is empty. Any tips?
P.S.: Here is my eclipse project (exported as a zip-archive) in case it sheds any light on things: https://dl.dropbox.com/u/9162958/scraper.zip
My guess is that "Convert to Maven project" is the trouble. This likely has changed the Eclipse classpath for the project from the bnd default bin folder to 'target/classes'. Can you confirm that it works without converting to maven?
bnd can work with other places for the bin folder, you must set the ${bin} property (preferably in cnf/build.bnd). There are some writeups how to use bndtools with maven. The reason that bnd does not follow Eclipse's settings here is that they are not available without Eclipse and a design goal of bnd is that it builds anywhere: the bnd file must therefore be the final arbiter of information.
Anyway one more tip ... activators are not the right way to build OSGi builds since they are an evil singleton. Declarative services is far superior and we should actually have used a similar mechanism when we designed OSGi.
My setup:
Eclipse Luna 4.4.0 (20140612-0600)
Bndtools 2.3.0.REL-20140510-023245
Here is how I made it work:
I downloaded you exported scraper.zip.
Created and empty workspace in Eclipse.
Imported your project from the ZIP archive into the empty workspace.
The default cnf project was automatically created.
By default, bnd is configured to use the bin directory for compiled *.class files while your Eclipse project is configured to use target/classes. Therefore, I had to change this settings in cnf/build.bnd by adding a single line:
########################
## BND BUILD SETTINGS ##
########################
bin: target/classes
Now, after cleaning and rebuilding the project, bnd creates generated/scraper.jar that contains your Activator.class.
Notes:
You could also adapt your project configuration to use the bin directory instead of target/classes but I assume that you will use Maven later on.
When using bndtools, it sometimes helps when you start with an empty workspace and import your projects one-by-one.
There is a bug in bndtools 2.4 which causes some problems if there are multiple source directories per project. Therefore, I'm still using version 2.3

Resources