How to automate Gradle task running - java

The project I am working on is Java, Gradle based. So I want to create a plugin/script that will run a certain Gradle task whenever I made changes to one of the files from the project.
For example
There is A.xml file and a B Gradle task. Whenever I do changes to A.xml and save it I want the B Gradle task to be run.
I am using IntelliJ IDEA, and my initial thoughts are that it could be solved through plugins/scripts.
Can you suggest where to start? Should it be done through plugins? Maybe there are automatisation settings in IntelliJ that have file watchers or smth. Thanks.
I tried to search similiar plugins, and didn't find any. Read documentation for plugin creation, I think I can reach the result, but isn't it overhead?

Related

IntelliJ doesn't run updated code and runs code from previous branch

I have a project that uses a Java test framework (cucumber) to run against a Python job (does some SQL querying)
The project is build with Gradle and spins up a docker instance for the Python environment to run the tests against.
However debugging is proving difficult because When I make chances to the python code it is not picked up when rerunning the tests - resulting in the same result (failure) as the previous run.
I noticed the Build files are not being updated, but even when i have done this manually and re-ran the tests again I get the same result.
I have tried 'Invalidate Caches/Restart' but had no joy.
I have tried reimporting the project but no joy.
I then tried to swap branch back to master and ran the 'working' tests but got a failed result that would only have come from the code in the feature branch.
My knowledge is a limited but a logical guess is the code is being packaged/wrapped up somewhere and not being refreshed(cached) on each test run.
I have also tried deleting IntelliJ's run configuration for the tests.
So I am now a little lost to where it could be caching this so I can clear it and hopefully it picks up the new changes.
Thanks
Did you looked in the gradle build output? try running the gradle build with --info, that will show you if the gradle build identify the changes in the python files or not.
If not , add the python sources to jar task dependencies:
task createJar(type: Jar) {
inputs.files(myPythonfolder)
..
it can also be achieved by adding new task with input files on the python sources and adding dependency between the jar task and the python task:
jar.dependsOn myPythonTask
for more accurate details , add the build.gradle file of your project here

Jenkins: Build and Run Maven Project

I am currently thinking about the potential solutions for building and running a Jenkins Maven project. I am a Jenkins Noob and what I currently think of is providing a Maven Plugin that runs the project right after the build and test phase. This feels wrong... .
So my basic question is, is it possible in Jenkins to configure a process to build a maven project and execute it right away and taking care for not interfering with it by starting another process and rebuilding it since a change arrived.
If this is possible it would ease the task by omitting the "Let's write a Maven plugin".
What do you means by 'execute'? Your program is a jar? If you do have to deploy it, there is tools in Jenkins to deploy with the build phase. If not, I think you can always make a 'Post build' command like java -jar nameofprogram.jar
In Jenkins you can configure jobs to execute multiple Maven targets when the jobs are run. I don't know if this answers your question, but you should be able to accomplish what you want by using "post build steps" and trigger certain behaviour from there.

Why is my IDEA gradle.build script not importing Guava?

I have never really done build automation before, but I'm trying to learn how to use Gradle. I never was interested in build automation but I'm finding it increasingly necessary nowadays.
I'm trying to create a new IDEA project. It has some dependencies on Guava immutable collections. I implemented the following gradle.build script.
But no matter how I try to run the build, or clean/rebuild the project... the Guava library never seems to be included in the project and the compile errors remain.
What exactly am I doing wrong? What tasks am I missing to get this to compile with all the dependencies?
Open Gradle tool window and click refresh button.

How to run Jmeter performance scenarios through maven project?

I have created some scenarios for my web application in Jmeter. I want to automate the process in maven project so that i can get good result as well as proper graphical representation.
What should i do to setup maven project which will take .jmx files created in Jmeter as input and runs.
I googled it, there i found some solutions but no solution is from scratch.
As i am new to this, i dont know how to download maven plugin/repository.
Please tell me what steps i need to follow.
Thanks in advance.
This can be done from scratch, but the Maven JMeter plugin has made it easier.
http://jmeter.lazerycode.com/
The documentation there makes it pretty easy.
Add Plugin to your Project
Put your JMX files in src/test/jmeter
run : mvn verify
There is a google group for that plugin as well https://groups.google.com/forum/#!forum/maven-jmeter-plugin-users.

Including .jar files in Github for consistency

I am new to using github and have been trying to figure out this question by looking at other people's repositories, but I cannot figure it out. When people fork/clone repositories in github to their local computers to develop on the project, is it expected that the cloned project is complete (ie. it has all of the files that it needs to run properly). For example, if I were to use a third-party library in the form of a .jar file, should I include that .jar file in the repository so that my code is ready to run when someone clones it, or is it better to just make a note that you are using such-and-such third-party libraries and the user will need to download those libraries elsewhere before they begin work. I am just trying to figure at the best practices for my code commits.
Thanks!
Basically it is as Chris said.
You should use a build system that has a package manager. This way you specify which dependencies you need and it downloads them automatically. Personally I have worked with maven and ant. So, here is my experience:
Apache Maven:
First word about maven, it is not a package manager. It is a build system. It just includes a package manager, because for java folks downloading the dependencies is part of the build process.
Maven comes with a nice set of defaults. This means you just use the archtype plugin to create a project ("mvn archetype:create" on the cli). Think of an archetype as a template for your project. You can choose what ever archetype suits your needs best. In case you use some framework, there is probably an archetype for it. Otherwise the simple-project archetype will be your choice. Afterwards your code goes to src/main/java, your test cases go to src/test/java and "mvn install" will build everything. Dependencies can be added to the pom in maven's dependency format. http://search.maven.org/ is the place to look for dependencies. If you find it there, you can simply copy the xml snippet to your pom.xml (which has been created by maven's archetype system for you).
In my experience, maven is the fastest way to get a project with dependencies and test execution set up. Also I never experienced that a maven build which worked on my machine failed somewhere else (except for computers which had year-old java versions). The charm is that maven's default lifecycle (or build cycle) covers all your needs. Also there are a lot of plugins for almost everything. However, you have a big problem if you want to do something that is not covered by maven's lifecycle. However, I only ever encountered that in mixed-language projects. As soon as you need anything but java, you're screwed.
Apache Ivy:
I've only ever used it together with Apache Ant. However, Ivy is a package manager, ant provides a build system. Ivy is integrated into ant as a plugin. While maven usually works out of the box, Ant requires you to write your build file manually. This allows for greater flexibility than maven, but comes with the prize of yet another file to write and maintain. Basically Ant files are as complicated as any source code, which means you should comment and document them. Otherwise you will not be able to maintain your build process later on.
Ivy itself is as easy as maven's dependency system. You have an xml file which defines your dependencies. As for maven, you can find the appropriate xml snippets on maven central http://search.maven.org/.
As a summary, I recommend Maven in case you have a simple Java Project. Ant is for cases where you need to do something special in your build.

Categories