I want to generate my feign client code using swagger-codegen, but I cannot find the docs which can lead me to do it.
I have a microservice using spring cloud, several api-services using spring-cloud-feign interfaces to request the data.I wish that i can generate the feign client code.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>http://localhost:9141/v2/api-docs?group=building-service-api</inputSpec>
<language>java</language>
<output>${project.build.directory}/generated-sources/swagger</output>
<library>feign</library>
</configuration>
</execution>
</executions>
</plugin>
language/library set to 'java/feign', there are only models without feign client;
language set to 'spring', 'feign' is unsupported library.
I am confused how to generate all my code? There seems to be almost no guideline or doc or demo?
Add spring-cloud-starter-feign dependency in your pom.xml and:
<configuration>
<language>spring</language>
<library>spring-cloud</library>
</configuration>
Related
I just configured Maven to generate my Hibernate JPA meta-model but now I'm in doubt about how to manage it. What is the best practices to work with meta-model class?
Generate it in src folder
Keep it in target/generated-sources/annotations (Maven does it automatically)
If #2 is best choice, how do I add it to Eclipse build path when I import Maven project? I'd like to do it automatically, without the need to configure each project.
Update(21/06/2016)
Based on Michele's advice, I updated and found a working solution.
1) To generate Meta model, just add this dependence to :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.2.0.Final</version>
</dependency>
2) Add this plugin to pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/annotations/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Has anyone had success following the Eclipse Annotation Processing directions for GWTP Boilerplate Generation? I followed the directions for Eclipse Annotation Processing, but cannot import the GWTP annotation package.
I'd appreciate any insight on either Eclipse Annotation Processing, or the alternative Maven Configuration setup that is mentioned also.
These are the directions from GWTP Boilerplate Generation (bottom of page):
Eclipse Annotation Processing
In Eclipse, the annotation processor kicks in as soon as you save the file you're working on and incrementally
changes only the required files. Another method exists by using the Eclipse lifecycle mapping. If the lifecycle
mapping is used, the annotation processor doesn't have to be setup. Find out more in the Maven Configuration on
how to setup the annotation processing with out touching eclipse properties.
To enable GWTP annotation processing in eclipse:
Open the properties for your project
Ticking all the boxes on the Annotation Processing page.
Ticking all the boxes on the Annotation Processing page.
Add the GWTP jar to the factory path.
Add the GWTP jar to the factory path.
In maven you can try this:
1) Import gwtp processors
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-processors</artifactId>
<version>${gwtplatform.version}</version>
</dependency>
2) use next plugins
<!-- Run annotation processors on src/home/java sources -->
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-apt</artifactId>
<version>${gwt.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/apt</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
The project is a multi module maven project with 90% of the source code written in Java (there's a small bit in Scala). The unit tests are 80/20 java/scala, and the integration tests are 20/80 java/scala.
I tried Clover, but (at this time) it doesn't support scala.
I tried Jacoco. First I ran into problems getting any results due to the mutli-module configuration, but now using Sonar I've got the java coverage shown (thanks http://www.aheritier.net/maven-failsafe-sonar-and-jacoco-are-in-a-boat/). I used timezra (http://timezra.blogspot.com/2013/10/jacoco-and-scala.html) with jacoco, but that only analyzed the small bit of source code that is scala.
I started to try Scoverage, but that seems to have the same problem as timezra (it analyzes scala-to-scala, not the mix that I have). I therefor haven't even tried scct or undercover.
Is there any tool that handles mixed java/scala?
I would suggest to have two separate coverage tools for Java and Scala. More specifically, use Scoverage for Scala (with plugin for Sonar).
The reason is that for Java you would probably like to measure line coverage where for Scala it's much better to measure statement coverage. Simply said because there are many statements on a single line in Scala and you would like to measure which of them were invoked. I've written an article about this.
to answer my own question, Jacoco does analyze coverage for Scala tests and Java code. I haven't seen anything that does the opposite (but we don't have any Java tests for Scala code, so that didn't matter).
As for combining coverage, Rado's answer of using two tools makes sense.
Here's the changes I did to my pom to get coverage. NOTE, I'm creating Jacoco reports when the test runs, then later using Sonar for more analysis:
properties:
<!-- Jacoco and Sonar config properties -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<jacoco.version>0.7.2.201409121644</jacoco.version>
<sonar-jacoco-listeners.version>1.4</sonar-jacoco-listeners.version>
<jacoco.outputDir>${basedir}/target/</jacoco.outputDir>
<jacoco.out.ut.file>jacoco-ut.exec</jacoco.out.ut.file>
<jacoco.out.it.file>jacoco-it.exec</jacoco.out.it.file>
<sonar.jacoco.reportPath>${jacoco.outputDir}/${jacoco.out.ut.file}</sonar.jacoco.reportPath>
<sonar.jacoco.itReportPath>${jacoco.outputDir}/${jacoco.out.it.file}</sonar.jacoco.itReportPath>
Failsafe:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>-Xms512m -Xmx1024m ${jacoco.agent.it.arg}</argLine>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
<reportsDirectory>${jacoco.outputDir}/surefire-reports</reportsDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
jacoco:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-ut-agent</id>
<phase>process-test-classes</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<propertyName>jacoco.agent.ut.arg</propertyName>
<append>true</append>
</configuration>
</execution>
<execution>
<id>prepare-it-agent</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>jacoco.agent.it.arg</propertyName>
<append>true</append>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.reportPath}</dataFile>
</configuration>
</execution>
<execution>
<id>integration-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}</dataFile>
</configuration>
</execution>
</executions>
</plugin>
surefire:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>${jacoco.agent.ut.arg} -Xms512m -Xmx1024m</argLine>
<skipTests>false</skipTests>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
<reportsDirectory>${jacoco.outputDir}/surefire-reports</reportsDirectory>
</configuration>
</plugin>
added dependencies:
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>${sonar-jacoco-listeners.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-surefire-plugin</artifactId>
<version>3.3.2</version>
<scope>test</scope>
</dependency>
It is possible to see the mix of the two languages coverage.
With sonar is not possible, because it only analyzes one kind of language.
If you use jenkins, and configure a step that collect coverage reports(Jacoco), you will see the mixing the two languages.
I need to create a list of subclasses for a particular interface during maven build process and then use that at runtime to load those classes. I have added reflections-maven (from google code reflections) in my webapp pom but during maven build, its only including the classes from the web application and not the classes inside the packaged jars that are there in web-inf/lib folder of that application. Below is the straight forward configuration I have used. I looked at the plugin source code and it seems it scans the following: getProject().getBuild().getOutputDirectory().
Is there anyways I can configure the plugin to scan the dependent jar files of the project?
<plugin>
<groupId>org.reflections</groupId>
<artifactId>reflections-maven</artifactId>
<version>0.9.9-RC1</version>
<executions>
<execution>
<goals>
<goal>reflections</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
You can easily run Reflections with any configuration you like, using, for example, gmaven-plugin:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
new org.reflections.Reflections("f.q.n")
.save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
</source>
</configuration>
</execution>
</executions>
</plugin>
So all you need to do is to use the right configuration, maybe in your specific case:
def urls = org.reflections.util.ClasspathHelper.forWebInfLib()
new org.reflections.Reflections(urls)
.save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
I created a webservice and would like to generate documentation for the API. So I looked into Enunciate downloaded the maven enunciate plugin. However I get the below error on compile as the webservice annotations are on my interface class that my POJO implements rather than the POJO itself.
I don't want to clutter the POJO by adding the annotations to it.
artifact org.mortbay.jetty:maven-jetty-plugin: checking for updates from central
[INFO] [enunciate:docs {execution: default}]
[INFO] initializing enunciate.
[INFO] invoking enunciate:generate step...
[WARNING] Validation result has errors.
/Users/vkumar/IdeaProjects/identity-service/trunk/src/main/java/com/foobar/ids/service/IDService.java:17: [jersey] Jersey doesn't support interfaces as root resources.
The #Path parameter will need to be applied to the implementation class.
public interface IDService {
^
1 error
[INFO] ------------------------------------------------------------------------
The pom.xml snippet is here
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-plugin</artifactId>
<!-- check for the latest version -->
<version>1.20</version>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<!-- the directory where to put the docs -->
<docsDir>${project.build}/docs </docsDir>
</configuration>
</execution>
</executions>
</plugin>
That's a limitation of Jersey. You have to annotate your implementation class.
CXF, however, doesn't make that same requirement, so you may want to consider using the CXF implementation of JAX-RS instead of the Jersey implementation:
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-cxf-plugin</artifactId>
<!-- check for the latest version -->
<version>1.20</version>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<!-- the directory where to put the docs -->
<docsDir>${project.build}/docs </docsDir>
</configuration>
</execution>
</executions>
</plugin>