suppressing logging output during mvn compile

24 views
Skip to first unread message

Elango Cheran

unread,
Nov 17, 2015, 4:08:41 AM11/17/15
to clojure-ma...@googlegroups.com
Hi,
I like to have logging configured in such a way that behaves differently when running the program/uberjar vs. compiling/testing.  When running the program, I want logging output to go to a file in the directory from where the program was launched.  When just compiling or testing, I want there to be no file output from logging.

I use Maven when I write in Scala or Java, and the way I achieve this desired logging output behavior most simply is to have a separate log4j.properties in src/main/resources and src/test/resources.  The src/test/resources config file is honored during 'mvn compile' and 'mvn test', but the src/main/resources config file is what is included in the uberjar.

I'm writing Clojure code that I have integrated as a subjproject into a Maven project.  I did/do development via Leiningen, so I am going to maintain 2 build files that I will keep in sync (for as long as that is feasible).  But ultimately, the Maven pom.xml will be the canonical build file for my subproject.

I have achieved the desired behavior in my Leiningen project.clj.  The proper testing log4j.properties is honored during 'lein compile' and 'lein test', but the uberjar has the main log4j.properties.  Just as I would hope.

The strange thing is that when I run 'mvn compile', there is a logging output file created, and because 'mvn compile' gets called before most every other Maven phase, it's unavoidable in basically every Maven task.  

FYI, the pom.xml that I have created for Maven is based off of what I got from 'lein pom' and modified to handle a few other things (ex: using Expectations via JUnit).  Here is the relevant portion of my pom.xml: 

<build>
  <!-- configure dirs for sources, resources, output -->
  <sourceDirectory>src/main/clojure</sourceDirectory>
  <testSourceDirectory>src/test/clojure</testSourceDirectory>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
    </resource>
  </resources>
  <testResources>
    <testResource>
      <directory>src/test/resources</directory>
    </testResource>
    <!--<testResource>-->
      <!--<directory>src/main/resources</directory>-->
    <!--</testResource>-->
  </testResources>
  <directory>target</directory>
  <outputDirectory>target/classes</outputDirectory>
  <plugins>
    <!-- Clojure compiler -->
    <plugin>
      <groupId>com.theoryinpractise</groupId>
      <artifactId>clojure-maven-plugin</artifactId>
      <version>1.7.1</version>
      <extensions>true</extensions>
      <configuration>
        <sourceDirectories>
          <sourceDirectory>src/main/clojure</sourceDirectory>
        </sourceDirectories>
        <testSourceDirectories>
          <testSourceDirectory>src/test/clojure</testSourceDirectory>
        </testSourceDirectories>
        <runWithTests>false</runWithTests>
      </configuration>
      <executions>
        <execution>
          <id>compile</id>
          <phase>compile</phase>
          <goals>
            <goal>compile</goal>
          </goals>
        </execution>
        <!-- disable tests through clojure.test so that we can use
         expectations' testing lib's JUnit runner instead -->
        <!--<execution>-->
          <!--<id>test</id>-->
          <!--<phase>test</phase>-->
          <!--<goals>-->
            <!--<goal>test</goal>-->
          <!--</goals>-->
        <!--</execution>-->
      </executions>
    </plugin>
    <!-- add Java sources to the compile -->
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <version>1.7</version>
      <executions>
        <execution>
          <id>add-source</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>add-source</goal>
          </goals>
          <configuration>
            <sources>
              <source>src/main/java</source>
            </sources>
          </configuration>
        </execution>
        <execution>
          <id>add-test-source</id>
          <phase>generate-test-sources</phase>
          <goals>
            <goal>add-test-source</goal>
          </goals>
          <configuration>
            <sources>
              <source>src/test/java</source>
            </sources>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>


Is this an issue within clojure-maven-plugin?  If so, is there a workaround for this?  If not, where can I follow up on this?

Thanks,
Elango
Reply all
Reply to author
Forward
0 new messages