Hudson / default Maven - maven-2

i cannot figure out how to set a default maven. Within a job configuration if you add a Maven Build you have to specify a Version and the goal. The first item in the select box for version is "default". If you have specified other versions under "configure hudson" they will appear there too. However i want all my jobs to use the default. Do i have to set some kind of envoirment variable so hudson knows which maven version is the default one?
Thanks,
kuku

Try setting MAVEN_HOME and adding ${MAVEN_HOME}/bin to your executable PATH.

Interesting, I don't have the default option for maven. So either you have a different Hudson version (I run 1.376) or HUdson recognizes that you have set up maven on the command prompt. In this case the maven installation might not be complete/correct for the user Hudson is running under.
If that doesn't help, let us know what OS you are running on.

Related

Intellij - No valid Maven installation found when configured to use Maven Wrapper

I've upgraded my IntelliJ Community from 2021.1 to 2021.2 today and now I'm getting the following error when trying to run maven commands:
No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.
But it's correctly configured to use Maven Wrapper:
My .mvn/wrapper/maven-wrapper.properties is as follow:
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
What am I supposed to do in order to keep using Maven Wrapper? Or is it a possible bug?
It is a bug: IDEA-258757 Cannot start tasks with maven wrapper
UPD: This is fixed in versions 2021.3+

How to set environment vars in IntelliJ for Gradle tasks

the easiest way to pass spring profiles to gradle bootRun is (for me) by environment variable (e.g. SPRING_PROFILES_ACTIVE), when run on commandline.
Unlike the Application configurations, the config for gradle tasks does not provide an input for environment variables. And as VM options don't get picked up either as it seems, I can not run those tasks from the IDE.
I am aware, that I could start IntelliJ with the envvar set, but this seems rather cumbersome.
So what I need is the IntelliJ pendant for SPRING_PROFILES_ACTIVE=dev,testdb gradle bootRun, unless there is a good reason, they have left this out.
System is linux, intellij 14. The project in question is using springboot and I want to move over from running main in IntelliJ to running with springloaded+bootRun and separate compileGroovy calls as IntelliJ is not "understanding" the gradle file completely and therefor hides errors.
Make the System.properties available in the bootRun (or other) tasks.
bootRun.systemProperties = System.properties
This way we can set in IntelliJ VM Options like -Dspring.profiles.active=dev.
Here is my solution for setting up Spring environment variables / settings with Gradle / IntelliJ
Firstly, define a basic properties file, and then one based on your environment, such as:
#Configuration
#PropertySources(value = {#PropertySource("classpath:default.properties"),#PropertySource("classpath:${env}.properties")})
Int the above example, pay careful attention to the #PropertySource("classpath:${env}.properties"). This is an environment variable being pulled through.
Next, add a VM argument to IntelliJ (via the Gradle Tasks Run Configurations) - or as an argument via the gradle command line.
Lastly, copy the properties across in the gradle task as #cfrick mentioned and #mdjnewman have correctly shown:
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
bootRun.systemProperties = System.properties
}
I've had success adding the following to my build.gradle file:
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
systemProperty('spring.profiles.active', 'local')
}
This allows gradlew bootRun to be run from IntelliJ without requiring any changes to the IntelliJ Run/Debug Configurations (and also from the command line without having to manually specify a profile).

Can I commit and share VM options in IntelliJ?

To execute my application, or run or debug unit tests, I need to enable various VM options, include -javaagent:<aspectjweaver-path> or -Djava.library.path=<some native lib path>
I can see how to change these configurations manually in IntelliJ IDEA under "Edit Configurations..."
What, if anything, do I need to check in to my VCS to share these settings with other members of my team, and ensure they pick them up automatically whenever someone changes them in the VCS?
Alternatively is there a way to set these automatically in IntelliJ without even touching the edit configurations? Especially the aspectjweaver. When I build/test my project from the command line using maven this is all handled for me by specifying argLine arguments to the surefire plugin, but IntelliJ doesn't respect these settings. Perhaps there are alternative plugins that can help me out?
First, you need to share your run configuration. It's simply done by checking the Share box right to the configuration name in the run configuration dialog:
Your run configuration will then be saved to .idea/runConfiguration (or whatever your settings folder name is).
From Jetbrains Web Help:
If this check box is selected, the run/debug configurations become available to the other team members.
The shared run/debug configurations are kept in separate xml files under .idea\runConfigurations folder, while the local run/debug configurations are kept in the .idea\workspace.xml.
This field does not appear for the default run/debug configurations.

How to define Gradle's home in IDEA?

I am trying to import a Gradle project into IntelliJ, and when I get to the Gradle Home textbox, it is not automatically populated, nor will typing in the path of Gradle Home result in a valid location - I have the GRADLE_USER_HOME environment variable set (to what I think is!) the correct path, and I have been able to successfully import this same project into Eclipse. Any suggestions?
You can write a simple gradle script to print your GRADLE_HOME directory.
task getHomeDir {
doLast {
println gradle.gradleHomeDir
}
}
and name it build.gradle.
Then run it with:
gradle getHomeDir
If you installed with homebrew, use brew info gradle to find the base path (i.e. /usr/local/Cellar/gradle/1.10/), and just append libexec.
The same task in Kotlin in case you use build.gradle.kts:
tasks.register("getHomeDir") {
println("Gradle home dir: ${gradle.gradleHomeDir}")
}
Installed on a Mac via Homebrew, the path
/usr/local/opt/gradle/libexec
is preferable to
/usr/local/Cellar/gradle/X.X/libexec
since the former will survive version upgrades.
If you installed gradle with homebrew, then the path is:
/usr/local/Cellar/gradle/X.X/libexec
Where X.X is the version of gradle (currently 2.1)
If you are using IntelliJ, just do the following.
Close the project
(re)Open the project
you will see "Import gradle project" message on the right bottom. click.
select "Use default gradle wrapper". not "Use local gradle distribution"
That's all.
This is what helped me solve the problem of not having Gradle home set for the IDEA when importing a Gradle project.
THREE OPTIONS -- (A) Default Wrapper (B) "gradle 'wrapper' task configuration" OR (C) "local gradle distribution" defined by jetbrains: https://www.jetbrains.com/help/idea/gradle-settings.html
A. Default Wrapper (recommended)
If you are able, select this recommended option. If it is grayed out, see option C, which should then set your default for all subsequent projects.
B. Gradle 'Wrapper' Task Configuration
If you want IDEA to define your gradle version for you from your build script
Set this option if you define your gradle build versions as a task within your actual gradle build.
Example below from jetbrains: https://www.jetbrains.com/help/idea/gradle-settings.html
(useful if you do not want to share gradle builds between projects)
C. Local Gradle Distribution
1. Run the following command to get gradle location:
brew info gradle (if gradle was installed with homebrew)
2. You are looking for something like this:
/usr/local/Cellar/gradle/4.8.1
3. Next, append 'libexec' to the gradle location you just found:
/usr/local/Cellar/gradle/4.8.1/libexec
This is because "libexec is to be used by other daemons and system utilities executed by other programs" (i.e. IDEA). Please see https://unix.stackexchange.com/questions/312146/what-is-the-purpose-of-usr-libexec
4. Finally, put that new path in the Gradle home input box if IDEA prompts you.
IDEA should now have allowed you to hit OK
C:\Users\<_username>\.gradle\wrapper\dists\gradle-<_version>-all\<_number_random_maybe>\gradle-<_version>
\Android studio\gradle didn't worked for me.
And "Default gradle wrapper" wasn't configured while importing (cloning) the project from bitbucket
If it causes problem to figure out the path, here is my path :
C:\Users\prabs\.gradle\wrapper\dists\gradle-5.4.1-all\3221gyojl5jsh0helicew7rwx\gradle-5.4.1
This is instruction for MAC only.
I had the same problem. I solved it by configuring $GRADLE_HOME in .bash_profile. Here's how you do it:
Open .bash_profile (usually it's located in the user’s home directory).
Add the following lines to update $PATH variable:
export GRADLE_HOME=/usr/local/opt/gradle/libexec
export PATH=$GRADLE_HOME/bin:$PATH
Save it.
Apply your changes by running
source .bash_profile
I wrote my own article with instruction in a case if somebody will encounter the same problem.
On a mac it should ideally be at : /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1
(Replace the version string with the latest)
AFAIK it is GRADLE_HOME not GRADLE_USER_HOME (see gradle installation http://www.gradle.org/installation).
On the other hand I played a bit with Gradle support in Idea 13 Cardea and I think the gradle home is not automatically discover by Idea. If so you can file a issue in youtrack.
Also, if you use gradle 1.6+ you can use the Graldle support for setting the build and wrapper. I think idea automatically discover the wrapper based gradle project.
$ gradle setupBuild --type java-library
$ gradle wrapper
Note: Supported library types: basic, maven, java
Regards
If you're using MacPorts, the path is
/opt/local/share/java/gradle
I had to setup the Project SDK before selecting gradle path. Once that was set correctly, I had to choose "Use default gradle wrapper (recommended) in "Import Project from Gradle" dialog.
Still works if I remove gradle using brew:
$ brew remove gradle
This is where my gradle home is (Arch Linux):
/usr/share/java/gradle/
I had some weird errors where it could not find my class, I had to right click on my src folder (was red) to "Make Directory as" -> Source Folder Root
Click New -> Project from existing sources -> Import gradle project...
Then Idea recognized gradle automatically.
I couldn't get it to accept my Gradle JVM selection until I deleted a broken JDK
Th window below is from File -> Other Settings -> Structure For New Projects...
I had a red 1.8 JDK SDK entry here, once I deleted that Gradle JVM error below disappeared and I could move on to the next step
In case you are using Mac, most probably your gradle home should be /usr/local/gradle-2.0 for example.
In preference of IDEA search for gradle and set gradle home as given above.
It should work

Maven Artifact Search is always empty

When using Alt-Insert to insert a dependency into the POM, the Artifact Search is always completely blank regardless of what I search for.
I tried to add repo1 to Settings->Maven->Repository Services, it says "no repository found." I find that hard to believe.
I've also tried to "update" my local repository but that results in an error.
FYI I'm using Community Edition Snapshot.
Thanks!
If you have a brand new IntelliJ install and have never updated your Maven Repository, notice that there is a little "Update" button to the right that becomes clickable when you click on each repository.
Preferences > Build, Execution, Deployment > Build Tools > Maven >
Repositories
The important one is the https://repo.maven.apache.org/maven2/ remote repository, make sure you update it.
I used Artifactory to generate a settings.xml for me, and by default it pointed me to the "libs-releases" repository.
Instead want my "releases" repository to point to the much larger virtual repository "remote-repos."
All it took was a simple change to the options of the "Generate Settings" function.
Weird. The Artifact Search is working fine for me with IntelliJ Community Edition, at least for artifacts from the central repo that has been indexed:
And as you can see above, all repositories declared in POMs known by IntelliJ are listed.
There might be something wrong with your Maven settings. This is a wild guess but is your Maven home directory properly defined? Same for the user settings file? Is Maven actually working fine under IntelliJ?
Solved - by reinstalling Intellij Idea
Search for class tab in Maven Artifact Search popup was always empty
Solution in linux:
remove idea folder (for me it was ~/idea-YOUR_VERSION_HERE)
remove ~/.IntelliJIdeaYOUR_VERSION_HERE folder (settings)
download new version form jetbrains.com, unzip, run installer from bin
It appears to be a blocked port, as I am using my own artifactory repository. Of course, the port it is using looks to be completely undocumented, but WireShark shows it to be 58754. Sounds random, I hope it isn't!