My project is using Maven to compile both Java and Groovy classes.
My project compiles and builds just fine using maven but I would like IDEA (IntelliJ) to build it correctly as well. I use maven to generate the IDEA project file with the following command:
mvn idea:idea
I noticed it doesn't build the groovy files, only the java files.
I found out the issue was that by default IDEA was considering all the files not having a .java extension as resources.
When I generate the project file with the maven IDEA plugin I get the following in the ipr file
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
</wildcardResourcePatterns>
...
I have to modify it this way in order to have my groovy files compiling (and few others kind of files):
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
</wildcardResourcePatterns>
...
Note: this information can be found/edited as well in IDEA -> Settings -> Compiler -> Resource patterns
I can generate it correctly using the following command:
mvn idea:idea -DwildcardResourcePatterns="!?*.java;!?*.groovy;"
Does anyone know how to configure this in the pom.xml?
This need to be added in the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-idea-plugin</artifactId>
<configuration>
<wildcardResourcePatterns>!?*.java;!?*.groovy;</wildcardResourcePatterns>
</configuration>
</plugin>
Related
Hi I am completely new to Gradle. Can anyone please help me as to how I can convert this ant task into Gradle. I am trying to see if I can learn by example.
<property file="build.properties"/>
<path id="classpath">
<fileset dir="${ear.dir}/EarContent/APP-INF">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete file="${dist.dir}/*.jar" failonerror="false"/>
<delete failonerror="false">
<fileset dir="${build.dir}">
<include name="**/*.class" />
</fileset>
</delete>
</target>
<target name="init">
<mkdir dir="${dist.dir}"/>
<mkdir dir="${build.dir}/classes"/>
</target>
<target name="jar" depends="clean, init">
<javac srcdir="${src.dir}" destdir="${build.dir}/classes" debug="on">
<classpath refid="classpath"/>
</javac>
<jar destfile="${dist.dir}/phIntegration.jar">
<fileset dir="${build.dir}/classes" />
</jar>
</target>
I'm not convinced that trying move ANT build 1-1 to Gradle is a good learning exercise, although Gradle provides good integration with ANT.
Generally speaking, the build.gradle file for your project shall like somewhat like that:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'CLASSPATH_DIR', include: ['**/*.jar'])
//if you want you can use JARS from your filesystem as a classpath
//but you probably should use Ivy or Maven dependency management systems
}
sourceSets {
main {
java 'src/main/java'
//tweak the location of your source code, by default Gradle looks for sources in `src/main/java`
}
}
Once you invoke gradle clean build it will compile your sources and create a jar file containing the sources in build/libs directory. You can change the JARS name by adding the rootProject.name='your project name' in the settings.gradle directory.
The snippet uses Java plugin and the default behaviour of Gradle. If you want you can tweak its behaviour by using Delete Task or Jar Task.
If you define properly inputs/outputs of a task the init task won't be necessary since Gradle will take care of directories recreation if they're not existent. (Default tasks do that, if you start writing your own tasks you most probably will have to take care of that by your own)
I'm trying to trigger a custom build using the TeamCity 8.1 REST API (see https://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-TriggeringaBuild). My builds run fine and I'm able to specify custom branches and properties with no issue. My goal is now to specify a custom artifact dependency for the builds I'm triggering.
The response I receive when creating a build is something like the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<build taskId="1234" buildTypeId="buildConfig1" state="queued" ...>
<buildType id="buildConfig1" name="Build Config Name" ... />
...
<properties count="1">
<property name="testParam" value="Test 123" own="true" />
</properties>
<custom-artifact-dependencies />
</build>
The "custom-artifact-dependencies" tag in this response leads me to believe that there is a way to specify custom dependencies, but I have not found anything in the TeamCity documentation, the TeamCity forums, or from Google explaining how this can be accomplished. Is there something I'm overlooking here or another way of accomplishing this?
Adding the following to as a child of the "build" tag results in an "Artifact dependency should have type 'artifact_dependency'." error:
<custom-artifact-dependencies>
<artifact-dependency buildId="5432" buildTypeId="parentBuildConfig"/>
</custom-artifact-dependencies>
The server may be confusing my intention with the build configuration API for setting and viewing artifact dependencies (e.g. http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/artifact-dependencies/)
I had the same problem
This is what worked for me:
<build>
<triggeringOptions queueAtTop="true"/>
<buildType id="buildConfig1"/>
<custom-artifact-dependencies count="1">
<artifact-dependency id="0" type="artifact_dependency">
<properties>
<property name="pathRules" value="Artifacts_1.zip
Artifacts_2.zip
Artifacts_To_Unzip.zip!/**
"/>
<property name="cleanDestinationDirectory" value="true"/>
<property name="revisionName" value="buildId"/>
<property name="revisionValue" value="5432"/>
</properties>
<source-buildType id="parentBuildConfig" />
</artifact-dependency>
</custom-artifact-dependencies>
</build>
If the 'parentBuildConfig' build is still running, replace the buildId parameter with taskId
Some cvsrepository named Foo has several modules, f.e. module1, module2, ...
A buildscript does cvs checkout, compile and building the module.jar for all modules.
After the build has finished the filesystem looks like that :
Foo/module1/src
/bin
/module2/src
/bin
...
Now i want to use the sonartask like that :
Define the global sonar properties like sonar.username ... sonar.projektName=Foo for MainProject and sonar.modules=module1.module2,... for the modules.
Afterwards looping over the module folders, setting module specific sonar properties,
like sonar.projectName (for modulename) sonar.sources, sonar.binaries etc.
Looping works fine, but it seems as sonar wants a single build.xml for every submodule.
So i need another possibility for grouping modules.
I only found a commercial plugin => Portfolio Management plugin but need another solution.
-- EDIT --
I already found and tried to use the examples from github and documentation, but it seems theyrequire one main build file and a build.xml in every module folder.
Whereas my situation is different. There's only one build.xml that contains a javac + jar target for every module of my project. When build is done, the resulting filesystem looks like mentioned above.
The build is part of the deployment workflow which is driven by a xmlproperty file, that contains the projectname and all modulenames of that deployment job among other things.
Now after the build is done, in the next antfile i want to loop over the modules in that xmlproperty file via xmltask, pointing the module specific properties to filesystem, f.e. sonar.sources=/Foo/module1/src sonar.binaries=/Foo/module1/bin and call <sonar:sonar/> . Overriding of module specific properties in the loop is done via Flaka <let>
After all it's just looping over an existing filesystem setting the sonar poperties and calling the sonar task with approiate properties.
-- EDIT after comment --
Tried it like that :
build.xml
<project name="sonar" xmlns:fl="antlib:it.haefelinger.flaka" xmlns:sonar="antlib:org.sonar.ant">
<fl:install-property-handler/>
<!-- Import Sonar -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"/>
<!-- Import XMLTask -->
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<xmltask source="C:/WKS/Eclipse/372/sonar/props.xml">
<copy path="//project/name/text()" property="projectname"/>
<copy path="//module/*/label/text()" property="projectlabel"/>
<copy path="//module/*/name/text()" property="modules" append="true" propertyseparator="," />
</xmltask>
<property name="sonar.projectKey" value="${projectname}"/>
<!-- Set modules IDs -->
<property name="sonar.modules" value="#{replace('${modules}', '', ' ')}"/>
<property name="sonar.language" value="java" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<property name="sonar.host.url" value="http://somehost:9000" />
<property name="sonar.login" value="admin" />
<property name="sonar.password" value="admin" />
<xmltask source="C:/WKS/Eclipse/372/sonar/props.xml">
<call path="//module/*">
<param path="label/text()" name="modullabel"/>
<param path="name/text()" name="modulname"/>
<actions>
<fl:let>
sonar.projectName ::= replace('#{modulname}', '', ' ')
sonar.projectVersion ::= '#{modullabel}'
sonar.#{replace('#{modulname}', '', ' ')}.projectBaseDir ::= '${ant.working.dir}/build/projects/${projectname}/#{modulname}'
sonar.sources ::= '${ant.working.dir}/build/projects/${projectname}/#{modulname}/src'
sonar.binaries ::= '${ant.working.dir}/build/results/compile/${projectname}/#{modulname}'
</fl:let>
<!-- Execute Sonar -->
<sonar:sonar />
</actions>
</call>
</xmltask>
</project>
output :
Setting project property: modules -> Modul 1,Modul 2,Modul 3,Modul 4
Setting project property: sonar.projectKey -> Foobar
Setting project property: sonar.modules -> Modul1,Modul2,Modul3,Modul4
Setting project property: ant.working.dir -> c:\WKS\5513
Setting project property: sonar.language -> java
Setting project property: sonar.sourceEncoding -> UTF-8
Setting project property: sonar.host.url -> http://somehost:9000
Setting project property: sonar.login -> admin
Setting project property: sonar.password -> admin
Setting project property: sonar.projectName -> Modul1
Setting project property: sonar.projectVersion -> l_5_04_52_cd
Setting project property: sonar.Modul1.projectBaseDir -> c:\WKS\5513/build/projects/foobar/Modul 1
Setting project property: sonar.sources -> c:\WKS\5513/build/projects/foobar/Modul 1/src
Setting project property: sonar.binaries -> c:\WKS\5513/build/results/compile/foobar/Modul 1
parsing buildfile jar:file:/C:/WKS/Eclipse/372/DevJars/sonar/sonar-ant-task-2.1.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/C:/WKS/Eclipse/372/DevJars/sonar/sonar-ant-task-2.1.jar!/org/sonar/ant/antlib.xml from a zip file
Class org.sonar.ant.SonarTask loaded from parent loader (parentFirst)
[sonar:sonar] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
[sonar:sonar] Sonar Ant Task version: 2.1
[sonar:sonar] Loaded from: file:/C:/WKS/Eclipse/372/DevJars/sonar/sonar-ant-task-2.1.jar
[sonar:sonar] INFO: Default locale: "de_DE", source code encoding: "UTF-8"
[sonar:sonar] INFO: Work directory: C:\WKS\sonar
[sonar:sonar] INFO: Sonar Server 3.7.2
BUILD FAILED
C:\WKS\Eclipse\372\sonar\sonar.xml:41: The following error occurred while executing this line:
C:\WKS\Eclipse\372\sonar\sonar.xml:54: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
...
Caused by: java.lang.IllegalStateException: The base directory of the module 'Modul1' does not exist: C:\WKS\Eclipse\372\sonar\Modul 1
I tried also to set the basedir attribute to the value of my ${ant.working.dir}, where all binariues and src folders reside, didn't work either.
See documentation : http://docs.codehaus.org/display/SONAR/Analyzing+with+SonarQube+Ant+Task#AnalyzingwithSonarQubeAntTask-Multi-moduleProject
And example : https://github.com/SonarSource/sonar-examples/tree/master/projects/multi-module/ant
I had a similar problem. When you run the ant task from eclipse, sonar errors are not showed. so, I figure out the problem when the ant ask was executed from command console.
I had two problems:
The sonar.host.url property is mandatory
The sonar.projectKey could not contain special characters, for instance space
(I hope I phrased the title correctly!)
I have an ant buildfile which is referencing a maven pom like so:
<artifact:dependencies filesetId="dependency.fileset" useScope="compile">
<pom file="pom.xml"/>
</artifact:dependencies>
<copy todir="${jar.location}">
<fileset refid="dependency.fileset" />
<mapper type="flatten" />
</copy>
In pom.xml, some of the dependencies use a property in place of a hard-coded version number. But the copy task doesn't seem to resolve that property - it's trying to use "jarname-{app.version}" literally. I tried setting the value for "app.version" somewhere in the buildfile, to no effect. What am I doing wrong??
Thanks for any input!
As stated on the maven site, you should use artifact:pom to get that info:
<artifact:pom id="mypom" file="pom.xml" />
<artifact:dependencies filesetId="dependency.fileset" useScope="compile" pomRefId="mypom" />
If you have profiles to process:
<artifact:pom id="maven.project" file="pom.xml">
<profile id="my-profile"/>
</artifact:pom>
I am trying to get Spring MVC and Junit working with eachother and I am having trouble configuring the build.xml file. I am fairly new at using ANT and do not really understand all the tutorials. I put the junit.jar file in the lib direcotory, but still am getting the following message from my console.
test:
BUILD FAILED
C:\Java\mmz\WEB-INF\build.xml:63: The <classpath> for <junit> must include junit.jar if not in Ant's own classpath
Total time: 223 milliseconds
Edit
Here is an example of wanting to run just one test
and I am not sure what I need to do, i tried doing something like the following, but I dont quite understand what its doing, so I dont know how to make changes
<path id="classpath.test">
<pathelement location="" />
<pathelement location="${test.dir}" />
</path>
<target name="test">
<junit>
<classpath refid="classpath.test" />
<formatter type="brief" usefile="false" />
<test name="TesterTest" />
</junit>
</target>
I am pretty lost on what to do next. Thanks
If you copy-pasted your build.xml file then there is probably a classpath element somewhere. Probably near the top of the file. In that element they have probably listed some paths and/or files. You need to add the junit jar to this section.