Building a scala app with maven (that has java source mixed in)

前端 未结 7 1299
执笔经年
执笔经年 2020-12-07 09:05

I have an application where I would like to have mixed Java and Scala source (actually its migrating a java app to scala - but a bit at a time).

I can make this wor

7条回答
  •  庸人自扰
    2020-12-07 09:31

    Using the maven scala plugin, a config like the one below will work for a project that mixes java and scala source (scala source of course goes in the /scala directory, as mentioned by someone else).

    You can run run mvn compile, test etc... and it will all work as normal. Very nice (it will run scalac first automatically).

    For a great IDE, IntelliJ 8 works nicely: add in the scala plug in, then add a scala facet, and then adjust the compile setting for scala to run scalac first (critical if you have circular dependencies with scala and java source).

    
    4.0.0
    demo
    scala-java-app
    0.0.1-SNAPSHOT
    jar
    scala-java-app
    
        
            scala-tools.org
            Scala-tools Maven2 Repository
            http://scala-tools.org/repo-releases
        
    
    
        
            scala-tools.org
            Scala-tools Maven2 Repository
            http://scala-tools.org/repo-releases
        
    
    
        
            
                org.scala-tools
                maven-scala-plugin
                
    
                    
                        compile
                        
                            compile
                        
                        compile
                    
                    
                        test-compile
                        
                            testCompile
                        
                        test-compile
                    
                    
                       process-resources
                       
                         compile
                       
                    
                
            
            
                maven-compiler-plugin
                
                    1.5
                    1.5
                
            
          
    
    
        
            org.scala-lang
            scala-library
            2.7.2
        
        
            junit
            junit
            3.8.1
            test
        
    
    

提交回复
热议问题