Activate profile when finishing release using jgitflow Maven plugin? - java

I have a Maven profile documentation that I want to get activated when running mvn jgitflow:release-finish. I know that I can do:
mvn jgitflow:release-finish -Pdocumentation
because the documentation of the plugin states:
automatically copies any profiles (-P) and user-properties (-D) passed on the command line to the forked maven process when building
But that means that you cannot forget to add this profile manually.
Objective: I would like to be able to configure Maven so that this profile becomes active automatically (Or that I somehow can activate my profile when the 'release' profile is active).

The jgitflow:release-finish goal actually uses a default option useReleaseProfile defining:
Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate. If set to true, the plugin sets the property performRelease to true, which activates the profile "release-profile", which is inherited from the super pom.
This option has default value to true, hence when executing this goal will by default set the performRelease property to true.
Note that the release profile mentioned above is defined by the super POM, which is actually used by this plugin but also by the maven-release-plugin via the similar useReleaseProfile option.
You can then activate your profile based on this option as well, as following:
<profiles>
<profile>
<id>documentation</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
...
</profile>
</profiles>
This means that you can still esplicitely activate it via the -P option and that it will be automatically activated by the goal as well.

Related

How to increase the number of connections in maven

How can I increase the number of http(s) connections a maven build will use to download and upload Artifacts from the repository (Artifactory or similar).
I have seen this page:
https://maven.apache.org/guides/mini/guide-http-settings.html
But it does not say what is the parameter and syntax to set it.
I am using Apache Maven 3.6.0
according to Maven documentation By default, Maven 2.1.0+ will download up to 5 artifacts (from different groups) at once. To change the size of the thread pool, start Maven using following switch option to change default value:
-Dmaven.artifact.threads
for example :
mvn -Dmaven.artifact.threads=1 verify
You may wish to set this option permanently, in which case you can use the MAVEN_OPTS environment variable. For example:
export MAVEN_OPTS=-Dmaven.artifact.threads=3
There is options for maven:
maven.artifact.threads for configuring parallel artifacst resolution
You can use it as is described on site:
https://maven.apache.org/guides/mini/guide-configuring-maven.html
You can also add this properties to your settings.xml so will be affected for all builds:
<settings>
<profiles>
<profile>
<id>props</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.artifact.threads>10</maven.artifact.threads>
</properties>
</profile>
</profiles>
</settings>

Command line parameters specified in NetBeans 8.2 turns up when running .jar from command line

I have searched for a way to change this (unwanted) behavior.
I set command line arguments in Project->Properties->Run->Parameters and run my program in NetBeans IDE. Arguments gets passed to my program just fine, but they also turn up when I run the .jar from a .bat-file or .sh-script after it is compiled.
So my customer ends up having my test arguments activated if I forget to remove the settings from project settings before distributing my .jar.
I would have expected this info to be removed from the .jar. At least after compiling without debug information.
Is there a way to remove the arguments from my distribution without removing them from my project settings?
Anyone else having the same problem?
You could add a configuration (Project->Properties->Configurations->Add), select the created configuration under "Project->Properties->Run" and specify the arguments only for this configuration.
But this way is NetBeans specific. If you are using Maven you should use profiles. Add something like this into your pom.xml:
<project>
...
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!--your command line arguments-->
<exec.args>hello world</exec.args>
</properties>
</profile>
</profiles>
...
</project>
You still would need to remember to deactivate your development profile before shipping but like this you can separate the configuration between development and production system in a clean way. (Especially if later on there should be other configuration values which should differ, like logging level, different paths and so on).

How to run Junit test with a specific Category defined in a POM.xml using IntelliJ

I would like to know if using IntelliJ, is possible to run all test in the visual environment choosing a specific Junit category.
At the moment if you execute:
mvn clean test
you execute Fast Tests, but how to use IntelliJ to choose Slow or Fast?
Fragment of pom.xml
<profiles>
<profile>
<id>SlowTest</id>
<properties>
<testcase.groups>YOUR.PROJECT.test.categories.Slow</testcase.groups>
</properties>
</profile>
<profile>
<id>FastTest</id>
<properties>
<testcase.groups>YOUR.PROJECT.test.categories.Fast</testcase.groups>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
Many thanks in Advance
Juan Antonio
Your profiles are focusing the test run on specific categories. The JUnit Run/Debug configuration in IntelliJ also allows you to focus a JUnit run on a specific category.
You can access this configuration window from Run > Edit Configurations
Here's a screenshot showing a saved confoguiraiton named SlowTests which runs all tests having the category: com.stackoverflow.surefire.SlowTests:
You can save any such configuration by clicking on the file icon in the top left hand corner of this window and then that configuration will be available in the Run menu and you can even associate a keyboard short cut with it.
More information in the docs.
If you created your project using the pom.xml, in the "Maven Projects"-View you can activate the profiles you want to be active. There (Lifecycle) you can start the goal you want to be executed for each module as well.
How to get this: View->Tool Windows->Maven Projects

Shorter way for debugging Maven builds with eclipse

I have a Maven project in eclipse, which I run with a Run configuration. That configuration does compile and exec:exec with a script (called runner) defined in my pom.xml dependent on the OS (.bat in Windows, .sh in Linux). The runners do OS-dependent stuff and then start Java with my application. Which runner to use is specified with profiles like the following:
<profile>
<id>WINused</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<runnerForLaunch>${basedir}/src/runners/windowsRunner.bat</runnerToUse>
</properties>
</profile>
So, when I want to run it, I use Alt+Shift+X, M and select the Maven config. Later, I just use Ctrl+F11.
When I have to debug it, I have to do the following:
Edit the pom.xml to use another runner script that adds -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y to the Java call.
Launch the run configuration.
Launch a debug configuration that connects to the debugger.
My question is, can I somehow shorten that process? I regularly forget to undo my changes to pom.xml and use the runner I currently do not need.
Can't Maven somehow detect if I run it with Run as or Debug as and adjust variables depending on that?
If the runner config in your POM supports command line arguments:
Create another profile containing:
<profile>
<id>debug</id>
<properties>
<debugArgument>-agentlib: ...</debugArgument>
</properties>
</profile>
Use the new property in:
<runnerForLaunch>${basedir}/src/runners/windowsRunner.bat ${debugArgument}</runnerToUse>
Add debug to Profiles: in your debug configuration.
Use %1 or $1 at the Java call in your scripts.
Or:
Declare and supply a property value of <debugArgument>debug</debugArgument>.
Evaluate %1 or $1 in your scripts and call Java with different arguments accordingly.
Or:
Add a property debugArgument with 1) debug or 2) -agentlib: ... to Parameter Name / Value in your debug configuration.
Use the property in:
<runnerForLaunch>${basedir}/src/runners/windowsRunner.bat ${debugArgument}</runnerToUse>
1) Evaluate %1 or $1 for debug and call Java with different arguments accordingly or 2) use them at the Java call in your scripts.
Usually, you don't need to add debug options because eclipse simply adds them by calling "mvnDebug" instead of "mvn" when debugging a maven project. I suggest you simply run the shell script before you run your Java app, and start the Java app using exec:java in order to have it run inside the maven process that is attached to the eclipse debugger.

Selecting Maven Profiles in Intellij 14

I'm using intellij 14 and have the maven projects window open.
Why are there 2 different kinds of checkboxes? If you select the checkbox once, it will leave a white check. If you select it again, it will change the checkbox to gray. Whats the difference?
I also want to know how to tell a specific module (not the entire project) to use a particular maven profile that is only available to that module.
I have been unable to find this information on intellij's site.
Thanks!
There are three possible states for a profile:
Disabled:
Active:
Active by Default:
The last one is activated by setting something like this in your pom.xml
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>

Categories

Resources