I am looking to make my development life a little easier. Currently I have to go through multiple steps to deploy my code base to a test environment to allow for QA to do their work. These steps are not difficult just that I want to automate it so that it can auto run twice a day.
One thing that I am having trouble figuring out what to do is to automate my build artifacts phase in IntelliJ. I have two modules in my IntelliJ projects and I build artifacts for one of them.
The steps I go to build the artifacts are
Build --> Build artifacts --> Select Artifact to build
I was wondering if something like Ant would be able to do the job? I am not familiar with Ant, so I thought I was ask people opinions on it first.
Ant can do what you want, but personally I prefer Gradle or Maven to build my projects. You can use them even to deploy your app into test servers. Here's a simple tutorial for you to start learning gradle (my favorite one at the moment)
Usually what I do is have my run/debug also build my artifacts. On the bottom of "Run/Debug Configurations" in Intellij you can add "Build Artifact" to "Before launch: Make, Activate tool window".
You can probably build the artifact with ant by generating build.xml through Menu --> Generate Ant Build but would have to keep it updated. Maven or Gradle is a better option in this regard.
Ideally though, you would want a CI tool like Jenkins (there are others) to deploy your code to your environments. So when you push (with your VCS) or trigger it, everything is built by Jenkins and sent to where it needs to be for the QA team.
http://codurance.com/2014/10/03/guide-to-deploying-artifacts-with-jenkins/
To build Artifact from command line I used Ant.
These are the steps:
Install Idea Ant Generator Plugin
https://plugins.jetbrains.com/plugin/14169-ant-build-generation
and use "generate ant build ..." to create an ant xml file of your project (and modules).
Open Ant tool window and add the file generated.
Click build.all.artifact to test the build
Now download Ant from Apache repository https://downloads.apache.org/ant/binaries/
Unzip and add the folder to your SYSTEM PATH.
Now from command line:
ant -buildfile myfileant.xml build.all.artifacts
Related
I have a couple of projects in eclipse which I now manually export as plugins from eclipse with the following steps:
1) Right click on example_project_plugin_1 in the Project Explorer View
2) Select Export
3) Select Plugin Development > Deployable plug-ins and fragments
Then in the folder eclipse>plugins folder, I can see the archive/jar file of these plugins.
However I want to automate this system.
These plugins are required by another project (say project_to_test) which I'm trying to run and test and I am using Maven to automatically build test cases written using RCPTT running on a jenkins server.
So basically what I want is, without having to manually export as plugins from eclipse, it should be automatically exported as plugins when I call project_to_test from the jenkins server.
I found Tycho but it seems very complicated. (Maybe there's an easier way or tutorial somewhere of how to use Tycho for my particular use?) I tried Ant too but it's also manual work. Is there any easier way to do this? I am quite new to this so I need some direction.
Thanks in advance!
Tycho is probably the best way to do it, as you are already using Maven you should be well on your way. Tycho is simply an extension of Maven (plug-ins, but I am afraid to say plug-ins too many times with different meanings :-).
There is an excellent Tycho tutorial out there: http://codeandme.blogspot.co.at/p/tycho-articles.html so that is the place to start.
However, if you really really don't want to do that, then you probably want to use PDE Build. That is the traditional build system of Eclipse, but it has its weaknesses. You should know that Eclipse does not even use PDE Build to build itself anymore, it uses Tycho.
To use PDE Build from a command line you need to use Ant. The manual work that you refer to is (mostly) automated through a PDE feature that creates that Ant files for you. Right-click on a project, select Plug-in Tools -> Create Ant Build File
Once again, I feel compelled to encourage you to take the plunge into Tycho now, rather than invest more time in the PDE Build way. You are clearly ahead of the curve in other areas (you are doing GUI testing!) so now is the time for automating your builds too.
let's assume I have an android project in IntelliJ.
Now, I am changing some details on the strings.xml resource file, and after every change I build a new apk.
I want to create a second program that will automatically build an apk file. I could change the parameters for the strings.xml file, and then build automatically without accessing IntelliJ, is it possible? will it only be related to Java language? or could I build it in C# or any other language as well?
I did read about Maven and Ant, but I have no idea how to use them correctly, I would like an answer that will lead me to some examples or tutorials as well, thanks!
The common approach is to use three things:
Build system (Ant, Maven or Gradle) - for Android apps Gradle is
becoming standard
Version Control System (e.g. Git)
Continuous Integration Server (Jenkins, Travis or
other)
Gradle Build System
When you create default project in Android Studio, you already have it created with Gradle. Android Studio also allows you to convert project from Ant to Gradle. I cannot explain you, how to use Gradle in a single post, as it can be subject for whole article or even book. Basically, you have build.gradle file in which you can define dependencies in your project and build configuration. You can have installed Gradle in your system, but good practice is to use Gradle Wrapper, which is a single *.jar file and it can be used to build your application. Once you have your project configured with Gradle, you can build it from command line as follows:
./gradlew build
On MS Windows:
gradlew.bat build
Continuous Integration Server
When you have your project configured with Gradle, you can push its source code to your Git repository and create a job on your Continuous Integration server, which will be responsible for building your project. Within the build, you can create an artifact with compiled *.apk file, execute tests and run static code analysis. You can trigger your job via Git commit hooks or via polling on Continuous Integration server. It depends on chosen technology stack, but it can be automated.
If you want a lot of customization and free solution, Jenkins CI would be a good choice, but you'll have to configure a lot of stuff by yourself and host server by yourself. In my opinion, such choice can make sense in a team projects, when you have appropriate infrastructure and time to set it up. If you want an easy configuration and you're willing to spend some money or create an open-source project, I recommend using GitHub and Travis CI. It's also a good choice for individual developers. I'm not sure how to generate artifact with *.apk file on Travis CI, but I suppose it can be done and you can always ask support to help you. For sure, artifact be archived in Jenkins CI job.
I am absolutely new in Maven and I am studying it. I am using Eclipse
I have the following doubt: into Eclipse I have a Maven project.
If I select this project and I do right click on it and then I select the Run As option I have some choice. What exactly represent these choice? Are Maven tasks or what?
In particular to perform my project I have 2 possible choices:
Maven build
Maven build...
What exactly does these tasks? It seems to me that build the project and perform the related unit test. Is it true or am I missing something?
What is the difference between the previous choices. In the tutorial that I am following it is used the Maven build... and then set the clean package as goals. What exactly do this goal?
Tnx
The Developing with Eclipse and Maven - 4.2. Running Maven Builds doesn't really give any clue about the "Maven build" command.
So:
the "Maven build..." allows to define a new run configuration
the "Maven build" allows to choose between the existing user's run configurations or to create a new one if none exists.
About a user's run configuration with "clean package": have you ever used Maven? May be a good tutorial would be a first step... In the mean time - those goals will:
delete the target sub folder
rebuild the project in the new empty target sub folder
generate the archive jar-s as specified in the project pom
I would like to generate Eclipse Java Project with my Java program. When I click a button: it will generate an eclipse project with the parameters I specified (source path, library, ...)
My questions are:
is there a way to do that ? and how ? (api).
it is possible to generate Net-beans project too ?
Best regards,
Florent
Maven enables this and many more things around creating, bulding, testing and developing Java projects.
Create a Java project from command line. Then, using Maven create NetBeans, Eclipse or IntelliJ IDEA specific project files. Or even easier, just import already created Maven project directly from these IDEs.
Create Java Project in Eclipse first. Then look into directory created. You should find there two files: .project and .classpath. These are the files you should create in your app to get what you want.
Also for eclipse available M2Eclipse plugin to provide some Maven feature from Eclipse IDE.
http://m2eclipse.sonatype.org/
While Maven is the way to go in the long term, the best way to start a project in Eclipse is:
Hit Ctrl+N and choose Java project
Fill in the project name fields
Copy your files from wherever they are to the newly created project (ensuring to preserve package hierarchy)
Refresh project from File menu
Create a Run / Debug profile to run your app.
It should be fairly simple to get up and running this way.
The reason people recommend Maven is because Eclipse is an IDE. It's great for development but its no good for resolving external dependencies or for command line / automated builds. Maven is an IDE neutral way of building and becomes essential the more dependencies a project pulls in.
Unfortunately Eclipse integration with Maven is pretty clumsy and can be summarized with these very broad steps:
Install Eclipse Helios
Install m2eclipse from the Help | Eclipse Marketplace
Mess around with eclipse.ini to make Eclipse start from a JDK.
Configure m2eclipse to use any existing Maven local repository
Hit Ctrl+N and create a new Maven project and skip archetype selection
Copy all the source files from the old project into the new ensuring to use Maven's conventions for file locations. (e.g. source goes in src/main/java)
Create a Run / Debug maven target to clean / install the app
I say broad steps because there are a lot of gotchas. For example if the source is Java 5+ you might have to tweak the pom to set the compiler level. Best to get Eclipse working and then worry about Maven.
Netbeans has vastly better out of the box support for Maven although IMO Eclipse is still the better IDE for other reasons.
What is the most proper way to accomplish all of the following:
Create a project in Eclipse
With an Apache Ant buildfile
That Hudson (or another more recommended CI system?) uses
And support for JUnit tests that are run by both Ant/Hudson and Eclipse
And check the proper folder structure into SVN so that future developers can replicate the build, and Hudson can automatically grab from SVN and run the Ant file to build/test/deploy the project
And the project has native libraries, if that makes any difference (I've already written an Ant task that can download and unzip the proper library files depending on the OS)
I already have my project with some source files and an Ant file, but I've been having trouble integrating it with Eclipse in an organized manner, so I would really love to start from a fresh Eclipse project, set it up correctly, and then copy my Ant file and my source files piece-by-piece into the project in the most Eclipse-compatible way.
I will be continuing to play around with everything in an attempt to get it working as I like it. But if you have experience with this sort of thing, perhaps at your workplace, please give as much information as you can.
My main goal here is to learn this once and use it in my future projects. For now, I am developing a client-server application consisting of a JOGL applet frontend (using JNLP files) and an unattended server app. Up until now I've been doing it all by hand: writing and building in Eclipse, dragging the applet jar into my FTP client, SSHing the server jar and restarting it by hand, and all with no testing process. I'm hoping that by the end, the build process will be something like this: test locally on my machine with a copy of the native libraries; commit code changes to SVN; Hudson svn updates, uses the Ant buildfile to compile and run all JUnit tests; if all the tests pass, it proceeds to copy the server jar to my dedicated server and restart the running server instance, and then copy the client jar to my web server.
When I start a new project, I generally take the following steps:
Create a new Java project in Eclipse, using the Java project wizard and opting to keep source and class files in separate directories ('src' and 'class')
Set up the project in Eclipse with the package structure you want
Create a new repository (or folder in your repository) for the project, with the normal /trunk/ /branches/ /tags/ set up
Using your SVN client, import the contents of the project folder Eclipse made for the project (at the level where the 'src' and 'class' directories are) into the trunk of the repository
Confirm everything is in Subversion correctly (check the trunk out to a new location)
Using Eclipse, delete the project (and the files on disk)
Create a new project using the 'Checkout projects from SVN' wizard, using the trunk of the repository
Create your Ant script, ensure the project builds correctly, and add the Ant script to the repository
Now, from Hudson:
Create a new job and set the Subversion URL to the root of the repository
Add a build set that will use Ant (I've always had to install my own version of Ant and ensure it's configured correctly to have this work) and will call the Ant script you
Use 'Build Now' to see if the job will build correctly
You can invoke your JUnit tests from Ant in the build script (first compile them with the javac task, then run them with the junit task). Hudson will track the test results if you ask it to.
You can use a shell script build step to copy your server jar to where it's needed, and restart the server instance. Like Mnementh said, it sounds like you've got the native libraries sorted...
If you are not tied to using ant, and are prepared to use Maven, then it is simply a matter of setting up Maven with the Eclipse plugin which generates the Eclipse projects for you.
Hudson already knows how to build Maven projects, so that is taken care of.
So long as you can pull your projects into eclipse, then it will be able to run the unit tests, and hudson can use the previously mentioned maven support to run the unit tests as well.
If you use Maven, then you will want to follow it's guidelines on how to create a project, here is a good starting point.
Hope this helps.
At our company we actually use Eclipse, Java, Ant, SVN, Junit and Hudson. That is all you mentioned except the native libraries. If you said your ant-buildscript already works with the native libraries that problem seems solved too. To integrate it well into eclipse you could do it in two ways: Use Ant also from Eclipse (has downsides) or the developer has to install the native library for his machine properly, so that Eclipse can compile without a problem and for continuous integration it will be downloaded by Ant.