Gerhard Hagerer Gerhard Hagerer - 1 year ago 105
Scala Question

Local Java package management system in Python PIP style?

I want to program in Java or other JVM languages like Scala, Kotlin, or Groovy. When I am programming on my projects, I only want to have import statements in my Java/Scala/Kotlin source files without the need to state the packages a second time in a Gradle/Maven build script. Instead I want to work as I would do in Python, i.e. have my import statements at the beginning of my source files and I am done.

The packages should then automatically included when I am compiling if all packages are installed in a central local package management system or otherwise get an error message telling me that I have to install a missing package. It should essentially work the same as for Python and PIP respectively.

Is a workflow like this possible preferably with Groovy or Maven?

Thanks in advance!

Answer Source

The closest I can think is Grape:

Grape is a JAR dependency manager embedded into Groovy. Grape lets you quickly add maven repository dependencies to your classpath, making scripting even easier. The simplest use is as simple as adding an annotation to your script:

@Grab(group='org.springframework', module='spring-orm', version='3.2.5.RELEASE')
import org.springframework.jdbc.core.JdbcTemplate

Like in this example:

def parser = new org.cyberneko.html.parsers.SAXParser()
def page = new XmlParser(parser).parse('')
page.depthFirst().DIV.grep{ it.'@class'=='title' }.each {
  println it.A.SPAN.text()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download