EclipseLink Static Weaving with Intellij - intellij-idea

I'm using IntelliJ and I want my unit tests to be run or debug with static weaving for lazy loading et al. I know that unlike Eclipse that IntelliJ does not have a static weaving step but I imagine someone must have setup IntelliJ to statically weave before running or debugging tests.
So far I have tried dynamic weaving with the JVM argument of -javaagent:./path/eclipselink-2.5.0.jar but that doesn't seem to work. I still get these warnings:
[EL Warning]: metadata: 2013-08-28 11:00:51.091--ServerSession(1610028911)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [owner] for the entity class [class com.my.Contact] since weaving was not enabled or did not occur.
Do my IntelliJ brother and sisters just punt on this and skip weaving in the IDE? Do we just not use EclipseLink or have we figured out how to handle the static weaving and still use IntelliJ?
Thanks!

You can create additional build steps before launching a run configuration.
Run > Edit Configurations…
Select the desired run configuration
Add your static weaver compiler as additional build step under `Before Launch:
For example add a Maven goal like eclipselink:weave
Or execute a java process like java org.eclipse.persistence.tools.weaving.jpa.StaticWeave…
Position should be between Build and `Build artifact``
See Screenshot:
Another solution is to define the Maven goal as a hook for After Build in the Maven tool window. Just right-click on the appropriate Maven goal and select Execute After Build. This will execute the EclipseLink Weaver via Maven everytime after Build is executed. You will see the hook in parenthesis behind the Maven goal:

IntelliJ Idea can run additional targets to build the application.
If you have an maven project with staticweave plugin configured, it is possible to add a maven "process-classes" goal to perform staticweave actions automatically on idea build run.

Related

Intellij IDEA Run configurations for Cucumber runner class

I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!

How to automatically generate JAXB classes on build in IDEA?

I have an IDEA project that uses auto-generated JAXB classes from .xsd files. I have “client” and “server” modules that include a “common” module that contains, among other things, the JAXB classes.
I do not want to keep generated code under source control, but if the generated java classes do not exist, “client” and “server” modules do not compile. How to make IntelliJ automatically run JAXB before building?
There is no direct way to do it only with IntelliJ IDEA, you will need to use Ant or Maven or some other external process that will perform the code generation.
Check out jaxb2-maven-plugin.
In IntelliJ IDEA you can execute Maven or Ant before compilation.
In the build system's tool window you can bind a phase or a plugin goal to IDEA's build process.
For example the jaxb2-maven-plugin can be executed Before Rebuild or Before Build with a secondary click on the goal:
Another option would be to bind the goal to a lifecycle phase and execute the phase like 'generate-sources' before rebuild. In case of the jaxb2-maven-plugin the goal xjc is by default bound to the generate-sources phase of Maven.

setting classpath for gradle task / runconfig in intellij

I'm running unit tests in Intellij 14.1.2 with the Gradle plugin. I have external config and test data that is in environment specific in a set of directories (directory for each env). I want to load the config and data via the classpath.
In Eclipse I'd just add the env specific path to the run-config and save the config as:
'Test-XYZ-UAT1'
for example.
In intellij, it seems my application config classpath is tied to my 'module' classpath:
https://www.jetbrains.com/help/idea/2016.3/run-debug-configuration-application.html
how to add directory to classpath in an application run profile in intellij idea?
..which is bad enough but for the Gradle run configs I don't even have the option to add the module classpath.
Run/Debug Configurations window has no:
'Use classpath of mod...'
section.
Question:
How can I set the classpath of the run config when running a Gradle Task within Intellij ?
..and if someone could tell me how to get application run config specific classpaths setup that would be even better.
(please tell me I'm missing something ingenius about Intellij..)
Based on quite a bit of research and trial and error, here is the solution that works for my Kotlin based Spring Boot project.
Background:
My Spring Boot project run configuration is configured to use Run Gradle task in place of the standard IDEA build as its Before launch configuration (see screen shot below).
My Spring Boot project uses src/main/resources/application.properties for JPA and logging properties.
gradle build uses the following output directories for the build. These are the default gradle build output directories for a Kotlin project.
build/classes/kotlin/main for the main class files.
build/classes/kotlin/test for the test class files.
build/resources/main for the main resource files. This is where application.properties is copied during a build.
When I attempted to run this project inside IDEA using the run configuration above, it would fail during Spring Boot start up because it could not find application.properties inside the classpath. When I inspected the classpath used during application startup, build/resources/main was missing.
My Solution
Use the information from: Gradle Goodness: Delegate Build And Run Actions To Gradle In IntelliJ IDEA to delegate IDEA build and execution to Gradle.
When IDEA is configured to delegate build and execution to Gradle, the main and test modules should be configured as follows: On the Paths tab, select Inherit project compile output path.

Use findbug's surpresswarning annotations from eclipse in hudson

I got a hudson job which analyses the sources with findbugs. I'm currently using filters to surpress the warings but it would be better if I could surpress them directly in code.
I've seen that there is a findbugs plugin to analyse the code in eclipse and add annotations there. Do I need anything to make the annotations from eclipse work in hudson? The thing is I dont want to add FindBugs to the classpath of the projects... Is the eclipse plugin enouth and if yes what do I have to do to make it work in the hudson job.
The FindBugs annotation for suppressing false positives is #edu.umd.cs.findbugs.annotations.SuppressFBWarnings.
In order to use the FindBugs annotations, the following two JAR files must be on the Classpath:
annotations-x.x.x.jar (replace 'x' with FindBugs version number)
jsr305.jar
These files must be on the classpath of the process that performs the FindBugs analysis. They do not need to be on the classpath in production. In other words, you must add them to the Eclipse classpath and probably also in your build scripts (so that analysis works in Hudson). However, you do not need to deploy the files into production.
If you don't want to modify the projects' classpath, then it will probably not work in Hudson. It should work in Eclipse, although you will be required to put them in some global classpath, which is kinda dirty.

Maven plugin executing another plugin

I'm trying to create a new plugin to package my latest project. I'm trying to have this plugin depend on the maven-dependency-plugin to copy all my projects dependencies.
I've added this dependency to my plugin's pom, but I can't get it to execute.
I have this annotation in my plugins main Mojo:
#execute goal="org.apache.maven.plugins:maven-dependency-plugin:copy"
I've tried a few other names for the goal, like dependency:copy and just copy but they all end with a message saying that the required goal was not found in my plugin. What am I doing wrong?
Secondary to this is where to I provide configuration info for the dependency plugin?
Use the Maven Mojo executor by Don Brown of Atlassian fame to run any other arbitrary plugin.
The Mojo Executor provides a way to to
execute other Mojos (plugins) within a
Maven 2 plugin, allowing you to easily
create Maven 2 plugins that are
composed of other plugins.
Have you tried to create your own packaging type? Then you can define your own lifecycle mapping, i.e. bind goals to phases. In this case you can bind the dependency:copy-dependencies goal to your packaging phase and you don't have to wrap the goal into your own Mojo.
See also: How do I create a new packaging type for Maven?