Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of Travis CI yml file for java

I am new to Travis CI, but I have connected my Github to it. I have also created a .travis.yml where I set the language to java. I have created a HelloWorld.java file and committed and pushed it to the repo.

In Travis, there is no build at all. When I check requests under settings, I am seeing the commits, with the same status "Missing config", except for one stating "Build created successfully" but that has a red cross and red overlay when you hoover over it.

enter image description here

Is my .travis.yml missing a lot of commands and scripts as I have only set the language?

I dont have any build system as maven or the like on my mac installed, so the language setting won't suffice I guess. I need to put something in the script part for example:

jdk:
 - openjdk6
script:
mvn verify
after_success:
after_failure:

I need also to know what settings could be set for after_success and after_faliure.

Thanks, Sohail

like image 559
user2371684 Avatar asked Oct 21 '15 19:10

user2371684


1 Answers

Travis CI is NOT a build tool. It is a Continous Integration tool which usually executes the same build command you would do locally, but automatically after every push to GitHub.

It requires a build mechanism being active. Well, that is not totally true, but it requires you to specify a valid command in the script: section that can be executed on the Travis CI host trying to build your code. When the return code of the command is 0, the build is treated as SUCCESS. Otherwise, it is treated as FAILURE.

(This is all really simplified, best would be to read Travis CI documentation, and perhaps some documents about Continous Integration in general).

In short: Set up your project to use Maven or Gradle or your favourite build tool. You should be able to locally execute mvn clean verify (when using Maven). Then, set up your .travis.yml:

language: java
sudo: false
script: mvn clean verify

And commit & push it, together with the pom.xml (when using Maven). Now, Travis CI should work like a charm.

like image 90
Florian Albrecht Avatar answered Oct 24 '22 16:10

Florian Albrecht