{"id":15821,"date":"2018-10-21T07:40:49","date_gmt":"2018-10-21T07:40:49","guid":{"rendered":"https:\/\/blog.taragana.com\/?p=15821"},"modified":"2018-10-21T07:49:34","modified_gmt":"2018-10-21T07:49:34","slug":"how-to-rapidly-test-alternative-ideas-in-java-during-development","status":"publish","type":"post","link":"https:\/\/blog.taragana.com\/how-to-rapidly-test-alternative-ideas-in-java-during-development-15821","title":{"rendered":"How to rapidly test alternative ideas in Java during development"},"content":{"rendered":"\n

Problem<\/h2>\n\n\n\n

Java is a compiled language and in any non-trivial project you use multiple libraries which are neatly assembled for you when you run the application with your build system like gradle<\/strong>. This makes it hard and slow to test alternative ideas as you have to compile and run the project each time which is inconvenient and slow even in the best configuration.<\/p>\n\n\n\n

Solution<\/h2>\n\n\n\n

Groovy is an interpreted language (can be compiled too for performance) and is a super-set of Java. It is ideally suited for testing alternative approaches while development. However, how do you include your runtime classpath so that it can access all your classes as well as third party libraries that you use?<\/p>\n\n\n\n

There is a simple solution. You can add a task to your gradle build file. Here is a sample build file (build.gradle):<\/p>\n\n\n\n

plugins {\n    ...\n    id 'groovy'\n}\nmainClassName = 'com.taragana.App'\ndependencies {\n    ...\n    compile 'org.codehaus.groovy:groovy-all:2.4.14'\n}   \nrepositories {\n    jcenter()\n}\ntask(console, dependsOn: 'classes', type: JavaExec) {\n   main = 'groovy.ui.Console'\n   classpath = sourceSets.main.runtimeClasspath\n}<\/code><\/pre>\n\n\n\n

This build file contains the task console which can be run with:<\/p>\n\n\n\n

gradle console<\/code><\/pre>\n\n\n\n

In the console you can import and access any of your existing class files as well as third party libraries that you included in the application.<\/p>\n\n\n\n

Value Addition<\/h2>\n\n\n\n

This is also an instant test environment that you can use to test your tests before codifying them in test classes. This saves tremendous amount of time not only in coding but also in developing test cases.<\/p>\n","protected":false},"excerpt":{"rendered":"

Problem Java is a compiled language and in any non-trivial project you use multiple libraries which are neatly assembled for you when you run the application with your build system like gradle. This makes it hard and slow to test alternative ideas as you have to compile and run the project each time which is […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[144,145,146],"_links":{"self":[{"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/posts\/15821"}],"collection":[{"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/comments?post=15821"}],"version-history":[{"count":2,"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/posts\/15821\/revisions"}],"predecessor-version":[{"id":15824,"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/posts\/15821\/revisions\/15824"}],"wp:attachment":[{"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/media?parent=15821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/categories?post=15821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.taragana.com\/wp-json\/wp\/v2\/tags?post=15821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}