Why doesn't Eclipse m2e automatically add generated source folder to classpath? - java

I'm using 2018-12 with Java 8, but I'm running Eclipse itself with Java 11.
I have version "1.10.0.20181127-2120" of the m2e plugin.
I have a bunch of projects with similar characteristics. Maven projects run with Spring Boot. They are all stored in git.
For some reason, one of those projects was somewhat brain-damaged this morning. It still would build fine from the command line. Eclipse still knew it was a maven project, but it had no source folders. The .classpath file wasn't empty, it was just very minimal.
I got this particular problem resolved by simply copying the .classpath file from a similar project into this project. That fixed most of the problems, but I remembered that this one project uses a code generator plugin along with the "build-helper-maven-plugin" to indicate where the source is being generated. I found that Eclipse didn't have the generated sources folder as a source folder. I thought adding the "build-helper-maven-plugin" reference was what I needed to do to make Eclipse M2E to automatically detect this, but it doesn't appear to be working.
Once I manually added the generated sources folder as a source folder, that cleaned out the last compile errors.
This is a hopefully relevant excerpt from my pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/java-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.34</version>
<configuration>
<sourcePaths>
<sourcePath>${basedir}/src/main/schema/...</sourcePath>
<sourcePath>${basedir}/src/main/schema/...</sourcePath>
</sourcePaths>
<targetPackage>...</targetPackage>
<annotationStyle>jackson2</annotationStyle>
<useCommonsLang3>true</useCommonsLang3>
<useDoubleNumbers>true</useDoubleNumbers>
<includeAccessors>true</includeAccessors>
<includeAdditionalProperties>true</includeAdditionalProperties>
<sourceType>jsonschema</sourceType>
<generateBuilders>true</generateBuilders>
<includeJsr303Annotations>true</includeJsr303Annotations>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Update:
Deleting the Eclipse project and reimporting from git made no difference. Same result.

Related

why is 'dependency:copy-dependencies' executed unexpectedly during tycho build?

I want to add JARs to a plugin. Previously, I added them by hand but thought it would be a good idea to add them via dependency definitions.
I created a pom.xml in the bundle and added an execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/lib</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
As soon as I save the file the dependency JARs are all copied to the lib folder. So far so good...
When I start a tycho build, such as mvn install, the build succeeds but the lib folder now contains a new folder lib/myplugin-1.0.0.qualifier-lib and this folder contains copies of all the JARs in lib but they all have the extension .jar.jar.
If I remove the copy-dependencies execution before starting the tycho build then this folder is not created.
Can anyone explain why this is happening and what I should do to avoid this behaviour?

Eclipse project does not recognize Swagger Codegen artefacts

I added Swagger Codegen to my Eclipse project by modifying my pom.xml file directly:
<plugin>
<!--
Plugin that provides API-first development using swagger-codegen to
generate Spring-MVC endpoint stubs at compile time from a swagger definition file
-->
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger-codegen-maven-plugin.version}</version>
<executions>
<execution>
<id>generate-swagger-javaclient</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/swagger/remote-api.json</inputSpec>
<language>java</language>
<apiPackage>com.myproj</apiPackage>
<modelPackage>com.myproj.model</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<generateApiTests>false</generateApiTests>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<library>resttemplate</library>
</configuration>
</execution>
</executions>
</plugin>
If I run Maven update or the Maven generate-sources target, I get all the artefacts generated in my Eclipse project's /target/generated-sources/swagger/src folder.
However, Eclipse does not recognize them. Am I supposed to edit my Eclipse build path manually like some commoner, or is Eclipse supposed to recognize this new source folder automatically?
In Eclipse 4.9.0 (2018-09) I had to add the generated-sources folder as a source folder for the project like this:
open the "Navigator" view
browse to target/generated-sources (or whatever your folder for the generated sources is).
right-click on that folder
click "Build Path" -> "Use as Source Folder"
Menu Tree Screenshot
Does not solve the "Plugin execution not covered by lifecycle configuration" issue.
You can use build-helper-maven-plugin to add generated sources to you build path, if this plugin itself does not support it.
<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.basedir}/target/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
The answer, at this time, is that adding the generated source folder to the build path seems to be mandatory.
Ctrl+shift+R
Opens 'Open Resource' dialog box.
Besides the message line 'Enter Resource name ....' there is a drop down option.
When u click it, u get options as 'show status' , 'show derived sources' etc.
You must ensure that 'show derived sources' is checked.
Eclipse will start showing swagger generated artifacts as well.

Scala Maven Plugin not handling Scala source folder and reporting lifecycle error

I am trying to import a java+Scala project into Eclipse(v4.6.1 Neon). This consist a parent project with scala-maven plugin configured as follows:
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<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>
</plugins>
</pluginManagement>
While importing the project it show an error:
No marketplace entries found to handle scala-maven-plugin:3.2.1:add-source in Eclipse. Please see Help for more information.
While imported to eclipse, there is no source folder created in eclipse for scala(like for java src/main/java and src/main/resources). Also in child projects, it shows this Error.
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.2.2:add-source (execution: scala-compile-first, phase: process-resources).
Although I am able to build the project from command line.
I also have tried installing Scala IDE Plugin for eclipse, but nothing worked. I dont't want to mark this goal as ignored.
The goal add-source, should be used with "mvn eclipse".
But you seem to use m2e/m2eclipse, in this case did you install https://github.com/sonatype/m2eclipse-scala. this plugin setup your eclipse project to use scala + setup of scala folder.
From my personal experience, it's easier to mixe .java and .scala into the same source folder. Easier for IDE, build tools and dev (less directories to navigate into).
Hey PyThon read my answer here . It has the exact pom.xml that you need. It works great.

Maven dependencies not being compiled

I have been trying for the last hour or so to get my Maven project to include source files from its dependencies, but for some reason, it isn't. I have followed the steps provided by the following link, but when I compile and run the plugin, I get a ClassNotFoundException:
https://github.com/mkremins/fanciful
I have made sure to include the dependencies and the repository from the link above into my pom.xml file, but when I compile, they don't get added to my .jar file.
I am fairly new to using Maven, and like it so far, albeit that it can be a pain to solve issues like this.
I am building the project by doing the following:
Right click project -> Run As -> Maven Build -> Goal: clean install
EDIT -
With a little more searching around, I figured it wasn't as easy as I thought so. I added the following to my pom.xml build section:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>mkremins:fanciful</include>
<include>org.json:json</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
The only problem with this is that I needed to also manually include the dependencies of the main library I wanted to use - mkremins:fanciful; is there flag or option to automatically copy dependencies from the one file I need, rather than also including <include>org.json:json</include>?
Well, if you want to have your dependencies copied to your target jar, you need to tell maven to do so! Maven doesn't know if the artifact of your project is meant to be self-sufficient executable jar, jar to be executed inside a container or just a dependency or library for another project.
You might want to use copy-dependencies task from maven-dependency-plugin
For example:
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}</outputDirectory>
<excludeTransitive>false</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
For more tweaking you might also want to play with jar plugin and assembly plugin. On more about creating executable jars:
http://www.ibm.com/developerworks/java/library/j-5things13/index.html?ca=dat-
You have mistaken the idea of Maven. Maven is intended to use dependencies which are located in Maven Central. It's idea is not to compile dependencies. I recommend you to read about Maven and learn how it works.

How to include my *.jasper files together with *.class files in maven build?

I have a web project that was compiled by ANT. The *.jasper files were compiled with the *.class files. Once migrated to MAVEN they ceased to be integrated with the build.
I tried to include these file using the resource maven tag, but it seems that only include files that are in the resource. How do I tell maven to put them together (in the same folder) with the *.class?
You'll need a maven plugin for Jasper. I haven't used this myself but this should be exactly what you need
https://github.com/alexnederlof/Jasper-report-maven-plugin
Follow the usage instructions
<build>
<plugins>
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>jasper</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
</plugin>
</plugins>
And you should be good!
Update
Sounds like you have some config needs, to change your source directory
<configuration>
<sources>
<source>src/main/java/</source>
</sources>
<outputDirectory>(same as your java output)</outputDirectory>
</configuration>
I believe this will help you out!
I found the solution in this link: https://bowerstudios.com/node/976
In configuration tag, i put the tag:
<sourceDirectory>src/main</sourceDirectory>
And works fine!
Thanks a lot

Categories

Resources