Jenkinsfile DSL sourcecode - intellij-idea

I am developing new pipeline within Jenkinsfile using intelliJ.
When I was using jenkins 1 with pipeline-dsl plugin I could go into the source code and see how DSL was actually implemented in org.jenkins-ci.plugins:job-dsl-core. I would like to have the same ability with Jenkinsfile.
Can I somehow connect Jenkinsfile DSL and intellij to have there proper code completion and sourcecode insight?

In order to have access to the sourcecode for the Pipeline Plugin suite of plugins when working on ANY Jenkins pipeline script, whether global or otherwise, you will have to include the necessary libraries as dependencies.
I'm working on my current global pipeline library.
Here adding the CPS library via "Project Structure" menu item:
Go to Libraries
Click the add button and select "From Maven..."
Type in the correct GAV (in this case com.cloudbees:groovy-cps:1.9)
Click the magnifying glass button - IntelliJ will search Maven Central (and whatever other repos you've configured in the Maven IntelliJ configuration or via your settings.xml) and download them to an your local cache.
Rinse and repeat until you've got all the dependencies you need.
When you're done, it should look something like this:
I found that the minimum useful were:
com.cloudbees:groovy-cps:1.9
org.jenkins-ci.plugins.workflow:workflow-api:2.+

Have you tried this approach yet?

Related

IntelliJ (2020.2) - How disable 'Build project automatically' for a project based on Gradle?

I am an Eclipse/STS user/developer, now trying to use IntelliJ Idea (CE)
2020.2.(1,2,3)
For a project based on Gradle, how spring-integration, when I open the IDE it happens the following
Ok, let the IDE load the project ... but
From above, that is the problem, I don't want that the IDE starts automatically to build/rebuild the project. I just need, open the project and that's all.
Observation: for example in Eclipse/STS exists the option to disable Build Automatically
I did do a research in the Web and I read the following posts and questions:
How to disable automatic gradle builds?
IntelliJ IDEA “Build project automatically” apparently not working
Intellij IDEA Java classes not auto compiling on save
Sadly the dialog options were changed but ...
Therefore:
From above, seems nothing to do.
Observation: from above observe the Build project automatically option is disabled
Even with that disabled and after to restart the IDE, I must always stop manually the build process
So what is missing? or Do I need a special extra plugin to accomplish my goal?
The images that you show indicate that you are building with Gradle, but the Compiler option that you disable is relevant for building projects with Idea not with Gradle.
For the 2020.2 version, you need to do the following:
Open the Setting > Build Tools page.
Disable the "Reload changes in build scripts" option.
This way you can manually control the reload. When you change the build script, you will see a small gradle icon in the right side of the editor.
For more info, refer to the IntelliJ IDEA help > Gradle section.
https://www.jetbrains.com/help/idea/work-with-gradle-projects.html#auto_reload
There are two different things in IntelliJ's Gradle support that sometimes confused: sync and build. Your pictures demonstrate sync process (note caption on the toolwindow). Word build is kind of misleading here.
What is sync? In gradle we use Groovy to define the build procedure. Groovy is an imperative programming language, so it's hard to predict resulting dependencies graph without actually executing the script. During the sync Idea executes configuration phase of gradle build (one that builds dependency graph), and obtains configured objects from the Gradle daemon. This information is used to setup project in the IDE: modules, libraries, dependencies, which sources are test, which are prod, etc.
Actual build is not happening during sync. You can convince yourself by adding syntax error to any source file, and observe that the sync succeeds. But build will fail if you invoke it.
In answer to the original question: you can't disable automatic build, because it is not enabled.
Is it possible to disable sync in Gradle project? Short answer - no. If you need a code browser, which is not required to understand all the cross-references in the source code, IDEA is not the best choice probably.
TL;DR;
Without sync IDE does not know which files are sources, and which are not. IDEA cannot open folders. It only can open projects. Good thing is that module can contain folder. So you can do the following: File | New | Project. Select Empty project, Next, select some random folder outside the source folder you want to open, Finish.
Then add new module:
Select Java in the left panel, everything else keep default, Next, Finish. Then in new module remove existing content root, and add folder with sources as new content root
Resulting project is mostly useless. Tons of red code (at least, unresolved symbols from external libraries), no inspections, no navigation, no sense. But it might be useful in some rare situations indeed.

Gradle Script parameters(such as -Penv) with Intellij

Background:
I've been using Eclipse for a while and am trying out Intellij now.
I checked out my project from Git (via Intellij) and recognized it as a gradle project. Its created the WAR(& the exploded WAR) all of which are fine.
Question:
When I was using Eclipse, I used the command:
gradlew -Penv=Development :my_webapp:assemble
This used to do a few things including creating a environment.properties file that my dev specific env could use (for selecting database instances etc) based off of -Penv=Development...I'd like the Intellij gradle build to do the same... What's a way to configure Intellij's gradle process to do these custom things or provide same features as provided by this specific command line tool (Note - the code for this is already written in build.gradle file)...
I looked at some of Intellij's docs, but could not find an answer to this.
EDIT:
I've found the solution, for anyone interested - read on...
Seeking guidance from #Stanislav, I was able to add the property as follows:
In your server's run configuration (Run/Debug Configuration -->Your server's config(Jetty etc), there is a section called Before launch, which should have Make/Build Gradle already included
Hit the + sign -->Run Gradle Task --> Select your gradle project (i.e. the web app) --> Select the task (most likely loadEnvironmentConfiguration) --> set the script parameters such as -Penv=Development, hit OK
Move this to before the Build Gradle function (by using the up arrow - to the right of + sign you hit in step 2)
It seems, that you need to create your specific run or debug configuration. You can read about it in official IntelliJ Idea help. All you need, is to modify your configuration for the task you need, by providing the argument -Penv=Development, since it is running with gradle.
You may also need to define Gradle instance, which will be used via settings, if the defaul wrapper wont work for you. You can find almost all you need in the the official help.

Can't replicate simple akka project in intelliJ

I am a new scala user and am having problems getting a development environment functional.
I downloaded the typesafe activator which launches an editor in a web browser and was able to run the akka actor tutorial script fine.
However, I have set up my intelliJ scala/akka environment, and when copying the same sample code to intelliJ, I am getting compile errors. I have added akka 2.2-M1 via maven to my project.
Initially when I copy
import akka.actor.{ActorSystem, Props, Actor, Inbox}
the last "Inbox" library is highlighted in red, and on compile I get "Error: object Inbox is not a member of package akka.actor. It suggests that I add akka.actor.dsl.Inbox. When I do that the import is greyed out because it is "not implimented", and get a compile error further down in the script when I go to implement inbox. It says "
not found: value Inbox
val inbox = Inbox.create(system)
"
What am I doing wrong? Thanks!
I would recommend you use sbt and then use the gen-idea plugin to create your intellij project.
You'll need to re-run gen-idea every time your dependencies change - intelliJ currently won't automatically discover and resolve managed dependencies for you.
here is the plugin with directions.
https://github.com/mpeltonen/sbt-idea
also, as a professional I would recommend you use the sbt console for most of your tasks.
Ctrl-tab 0 will let you hop over there without touching your mouse.
Escape brings you back to the code editor window.
You can run sbt ~test to test on change to your files etc.
Note you may need to change focus off of intellij for it to save the file in memory if you're use ~test
I managed to resolve the same issue by adding the following library from the Maven repository
com.typesafe.akka:akka-actor_2.10:2.2-M3
to File -- Project Structure -- Libraries

IntelliJ with cucumber (java) and step definition location

Ok, so I'm working on a project using IntelliJ and trying to take advantage of its cucumber functionality. I've not worked with the java flavour of cucumber, but IntelliJ seems to want the step definition files in a specific location, relative to the feature files.
I found this: how to define step definitions location for cucumber in intelliJ 12 and other sources that pointed me to been able to add the "glue" property of my run configurations which tells cuke which package to find the step file. So I am at a point where I can run my tests via IDEA. BUT I need to set this every time I run a new test, as Ctrl+Alt+F10 or right click+run test will not start the test with this flag. Also, the ide support is screwed as IDEA doesn't know where the steps are, it doesn't auto complte or Ctrl+Click navigate to steps.
Is there a way to the the IDEA project to always look for steps in a given package both when running the tests and for its auto complete?
Creating self answer for others who might have this problem. My project did not have the steps marked as test source root, and although I DID do this, it was not until I closed and reopened my project that they were picked up. So a simple restart was my answer.
You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.
(IntelliJ 12.1.4)
Go File->Settings--> plugins
Install Cucumber for Java plugin
Then you can manage cucumber plugin as shown below
This should redirect you to step definition when you click your test.
Hope this helps
IntelliJ supports a plugin for Cucumber-Java/Groovy. Installing this plugin will enable the navigation from Steps mentioned in the feature file to the Step Definitions.
And after creating the Step Definition, navigation is easily possible
I go in EditConfiguration, Glue section and i put the path from the package above and the package where is your class for steps, ex:
CucumberFramework.stepsDefinitions
It is really nonsense :) but in in my case when IDEA refused to add steps definition automatically due to some plugins installed, e.g. Cucumber for Scala and suggested deleting them that i cant since i need them in other project. So, long story short, to add (Create step definition) you need to create Class in 'glue' dir and some fake Cucumber implementation, build one more time and it resolved my issue.
Background:
When I use IDEA 2018.2
And Java 8
And Cucumber info.cukes:cucumber-java:1.2.4
#When("^I created a Class and put there fake step implementation$")
#And("^I run gradle build one more time :)$")
#Then("^This Class will be able for me from the feature file by ALT+ENTER as usual$")
#And("^It resolved my issue when I was not able to automatically generate step definition$")

How to configure IntelliJ IDEA and/or Maven to automatically add directories with Java source code generated using jaxb2-maven-plugin?

In our project we are using jaxb2-maven-plugin to generate Java source code from XML Schema, which causes that our Maven module requires additional source code directory (in our case target/generated/main/java). Up to date I've been using Eclipse and maven-eclipse-plugin to import all the projects into Eclipse workspace. The plugin is (somehow) able to add the directory with generated source code automatically to Eclipse' .classpath file.
Recently I try to switch to (play with?) IntelliJ IDEA 9 (so I am a newbie in this environment) and I've noticed that additional source directory is not added during IDEA's importing process...
Is there any way I can configure IDEA/Maven to make importing directory with generated source code automatically?
The convention with Maven is to generate code in target/generated-sources/<tool>, for example target/generated-sources/jaxb2
Follow this convention and IDEA will add the folder as source folder (see IDEA-53198).
Generated code, using jaxb2-maven-plugin, was missing for me in Intellij 2017.1 whereas Eclipse Neon created it.
Fixed it from context menu of module by selecting 'Maven -> Generate Sources and Update Folders'.
Try with maven-jaxb2-plugin. If it does not work then it's IDEA problem.
In Maven you can add new source roots per configuration. Maven plugins can do this programmatically. This is for sure the case with maven-jaxb2-plugin. Then, if IDEA does not recognize it, then it's a problem on that side.
You can use the Maven Build Helper Plugin. It is located at http://www.mojohaus.org/build-helper-maven-plugin/
It allows to configure additional source roots. And the maven integration of IntelliJ will add the new source root. We are using this feature in quite a few builds and it works just fine. Tested with vers. 13 of IntelliJ IDEA.