Quarkus - Generate rest clients from OpenApi - openapi

I'm using Quarkus with Kotlin and tried to generate Rest clients using this Quarkus extension https://github.com/quarkiverse/quarkus-openapi-generator.
I included the dependency and the mentioned plugin into the pom.xml
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
<version>0.9.0</version>
</dependency>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
When compiling everything gets generated correctly into target/openapi/quarkus/clients_json/api/DefaultApi.java
However, when trying to import the DefaultApi it throws an error that it can't find the class.
I've tried the suggestions from the following post maven can't add files in generated-sources for compilation phase and included
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/gen-java</source><!-- adjust folder name to your needs -->
</sources>
</configuration>
</execution>
</executions>
</plugin>
into the pom.xml as well but it didn't do anything.
Does anyone know how to change the output directory of the generated OpenApi files with Quarkus?

Just an FYI:
I did the following, and it worked
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi</source>
<source>src/gen/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Related

How to generate Open API files on Bazel?

So we are migrating a Maven project to Bazel. In this project, we generated our Open API documentation from Java annotations and using the swagger-maven-plugin as follows:
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputFileName>swagger</outputFileName>
<outputPath>${project.basedir}/src/main/resources/webroot</outputPath>
<outputFormat>JSON</outputFormat>
<resourcePackages>
<package>com.example.package1</package>
<package>com.example.package2</package>
</resourcePackages>
<prettyPrint>true</prettyPrint>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
Is there a way to generate this file using a Bazel rule?

Unable to import java.io into a scala package in a mixed scala/java project

I have a mixed scala/java project. Why would the following import not work?
This error occurs both in Intellij and more importantly on maven command line using
mvn clean -DskipTests package
Here is the intellij SDK:
Here is the relevant section of the pom.xml showing the java/scala interaction - as recommended by https://davidb.github.io/scala-maven-plugin/example_java.html :
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is the error from maven command line:
[ERROR] /git/OCspark/tcpclient/src/main/scala/com/pointr/tcp/iotest/package.scala:2: object io is not a member of package com.pointr.tcp.java
[ERROR] import java.io._
[ERROR] ^
Update Based on a comment by # LuisMiguelMejíaSuárez I looked at the java sources. Note that java is not the root of the package hierarchy - which might have then been the more obvious cause of this problem:
But .. unmarking_ the java directory as sources does fix the problem..
Why would this fix it?

Generate two jars of same Maven project using different Scala version

I am having a Maven project with Scala code and i want to generate the two jars based on the different Scala versions (2.10.6 and 2.11.8).
If someone please suggest the solution how i can achieve this in single maven install execution or if there is any other way of achieving this in Maven using some Maven plug in.
I am able to solve this problem using multiple executions.
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-version-2.10</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.10.6</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.10</outputDir>
</configuration>
</execution>
<execution>
<id>scala-version-2.11</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.11</outputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>scala-2.10</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.10</classifier>
<excludes>
<exclude>scala-2.11/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>scala-2.11</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.11</classifier>
<excludes>
<exclude>scala-2.10/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Create profiles that have dependency overridden for different versions of Scala. You will need to run mvn install on both profiles. For more information see: different-dependencies-for-different-build-profiles-in-maven
Also you need to alter artifact name / version in profiles to make distinction between those two.

axis2 wsdl2code plugin only creates Arrays

When running wsdl2code maven plugin it only creates Arrays as opposed to wsdl2java plugin we were earlier using for ant. Following is the configuration.
Thanks,
Ash
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2.version}</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>net.flitech.faregate.api</packageName>
<wsdlFile>${project.basedir}/src/main/resources/wsdl/faregate.wsdl</wsdlFile>
<namespaceToPackages>http://faregate.flitech.net=net.flitech.faregate.api</namespaceToPackages>
<databindingName>xmlbeans</databindingName>
<generateServerSide>true</generateServerSide>
<generateServerSideInterface>true</generateServerSideInterface>
<generateAllClasses>true</generateAllClasses>
<language>
java
</language>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Fixed by setting java version. By default it was using version 4. I set it to version 1.5 using following settings. Its generating lists now.
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2.version}</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<options><javaversion>1.5</javaversion></options>
<packageName>net.flitech.faregate.api</packageName>
<wsdlFile>${project.basedir}/src/main/resources/wsdl/faregate.wsdl</wsdlFile>
<namespaceToPackages>http://faregate.flitech.net=net.flitech.faregate.api</namespaceToPackages>
<databindingName>xmlbeans</databindingName>
<generateServerSide>true</generateServerSide>
<generateServerSideInterface>true</generateServerSideInterface>
<generateAllClasses>true</generateAllClasses>
<language>
java
</language>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

scala code-coverage tool Cobertura on jenkins

I have difficulties with configuring Cobertura code-coverage tool in Jenkins to work with mixed Java/Scala project. Java classes works ok, but Cobertura don't analyze Scala tests.
Scala-specific configuration in my pom.xml:
<version.scala.plugin>3.1.0</version.scala.plugin>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check/>
</configuration>
<version>2.5.2</version
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<!--suppress MavenModelInspection -->
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<!--suppress MavenModelInspection -->
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
It works. It was some kind of proxy issue, once I made build healthy again and built it several times, correct code-coverage appeared.