I get this error while trying to build a project on Android Studio. It happens when trying to compress the final artifact with a binary file on res/raw/file.dat.
The solution like explained here: Maven corrupting binary files in source/main/resources when building jar
Is to add the file or res/raw folder to a "false" filtering on build. But the problem is that i configure my internal maven repository with JFrog Articatory following this: https://inthecheesefactory.com/blog/how-to-setup-private-maven-repository/en
The question:
How to convert this:
<project>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources/lib</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
...
</plugins>
</build>
</project>
Into gradle style:
def libraryGroupId = 'XXXXXXX'
def libraryArtifactId = 'XXXXXX'
def libraryVersion = '0.0.1'
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version libraryVersion
artifactId libraryArtifactId
artifact("$buildDir/outputs/aar/${artifactId}-release.aar")
}
}
}
artifactory {
contextUrl = 'XXXXXXXXXX'
publish {
repository {
repoKey = 'libs-release-local'
username = artifactory_username
password = artifactory_password
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
publishPom = true
}
}
I've tried using pom.xml but it kepts saying does not recognized TAG project in .xml file.
Thanks!!!
android {
sourceSets {
main {
assets.srcDirs = ['src/main/res/raw']
}
}
}
Related
Question
I have created own custom check for checkstyle and it works on commandline and via maven checkstyle plugin.
However via gradle checkstyle plugin, it occurs below error.
* What went wrong:
Execution failed for task ':my-project:checkstyleMain'.
> Unable to create Root Module: config {C:\Users\[path to my project]\build\tmp\resource\string8421659201972573805.txt}, classpath { ...many of classpathes. not "null" }.
Whenever exclude custom check from checkstyle.xml, the task works.
How to make custom check works on gradle?
Versions
checkstyle: 8.37
maven checkstyle plugin version: 3.1.2
gradle version: 5.6.2
Implementation
custom check
public class MyCheck extends AbstractCheck {
...
checkstyle.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
<module name = "Checker">
...
<module name="TreeWalker">
...
<module name="package.to.my.check.MyCheck"/>
</module>
</module>
Custom check class and checkstyle.xml are packaged into an artifact named "mycheck-module".
pom.xml (It works)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.37</version>
</dependency>
<dependency>
<groupId>package.to.my.check.module</groupId>
<artifactId>mycheck-module</artifactId>
<version>[version]</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
</sourceDirectories>
<configLocation>checkstyle.xml</configLocation>
<enableFilesSummary>true</enableFilesSummary>
<maxAllowedViolations>0</maxAllowedViolations>
<violationSeverity>warning</violationSeverity>
<consoleOutput>true</consoleOutput>
<failOnViolation>
false
</failOnViolation>
<propertyExpansion>
checkstyleSuppressionConfigDir=${project.basedir}
</propertyExpansion>
</configuration>
</plugin>
build.gradle (It does not work)
buildscript {
...
dependencies {
...
classpath 'package.to.my.check.module:mycheck-module:[version]'
}
}
...
// Set up checkstyle
apply plugin: 'checkstyle'
def checkstyleSuppressionConfigDir = file("${rootDir}/suppressCheckstyle")
checkstyle {
toolVersion = '8.37'
sourceSets = [it.sourceSets.main]
config = resources.text.fromString(getClass().getResourceAsStream('checkstyle.xml').text)
ignoreFailures = false
maxWarnings = 0
maxErrors = 0
configProperties.checkstyleSuppressionConfigDir = checkstyleSuppressionConfigDir
}
I have resolved myself.
You can add your dependency into checkstyle with [Append] in below:
build.gradle
buildscript {
...
dependencies {
...
classpath 'package.to.my.check.module:mycheck-module:[version]'
}
}
...
// Set up checkstyle
apply plugin: 'checkstyle'
def checkstyleSuppressionConfigDir = file("${rootDir}/suppressCheckstyle")
// ================ [Append] ================
dependencies {
checkstyle 'package.to.my.check.module:mycheck-module:[version]'
}
// ================ [Append] ================
checkstyle {
toolVersion = '8.37'
sourceSets = [it.sourceSets.main]
config = resources.text.fromString(getClass().getResourceAsStream('checkstyle.xml').text)
ignoreFailures = false
maxWarnings = 0
maxErrors = 0
configProperties.checkstyleSuppressionConfigDir = checkstyleSuppressionConfigDir
}
I'm a complete beginner with both Maven and Gradle. I have a working Maven project. Now I want to add a bunch of classes from another project which was built using Gradle. I want to take classes from the Gradle project and use it in my Maven project. When I copy the classes into my Maven project, I get a bunch of dependency errors. To resolve those errors I would like to add the required stuff to my pom.xml file.
Basically, I want to add all dependencies specified in a build.gradle file, to my pom.xml file.
The pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-core -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-jdk1.5 -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-jdk1.5</artifactId>
<version>0.7.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-ext -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-ext</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0-jre</version>
<!-- or, for Android: -->
<!-- <version>27.0-android</version> -->
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.trove4j/trove4j -->
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
</project>
The build.gradle file:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.rapidminer.com/content/groups/public/' }
}
}
plugins { id 'com.rapidminer.extension' version '0.8.2' }
// Define Maven artifact repositories
repositories {
jcenter()
maven { url 'https://maven.rapidminer.com/content/groups/public/' }
ivy {
url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/prom/"
layout "pattern", {
artifact "[module]-[revision]/[module]-[revision].[ext]"
artifact "[module]-[revision]/[artifact].[ext]"
ivy "[module]-[revision]/ivy-[module]-[revision].xml"
}
}
ivy {
url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/thirdparty/lib/"
layout "pattern", {
artifact "[module]-[revision]/[module]-[revision].[ext]"
ivy "[module]-[revision]/ivy-[module]-[revision].xml"
}
}
ivy {
url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/thirdparty/resource/"
layout "pattern", {
artifact "[module]-[revision]/[module]-[revision].[ext]"
ivy "[module]-[revision]/ivy-[module]-[revision].xml"
}
}
}
extensionConfig {
// The extension name
name 'RapidProM'
/*
* The artifact group which will be used when publishing the extensions Jar
* and for package customization when initializing the project repository.
*
*/
groupId = 'org.rapidprom'
/*
* The extension vendor which will be displayed in the extensions about box
* and for customizing the license headers when initializing the project repository.
*
*/
vendor = "Eindhoven University of Technology"
/*
* The vendor homepage which will be displayed in the extensions about box
* and for customizing the license headers when initializing the project repository.
*
*/
homepage = "www.rapidprom.org"
// enable shadowJar before rapidminer dependency (otherwise build fails)
shadowJar {
zip64 true
}
// define RapidMiner version and extension dependencies
dependencies {
rapidminer '7.2.0'
//extension namespace: 'text', version: '7.2.0'
}
}
// Define third party library dependencies
dependencies {
compile group:"org.rapidprom", name:"ProM-Framework", version:"31245"
compile "org.rapidprom:AcceptingPetriNet:6.7.93"
compile "org.rapidprom:AlphaMiner:6.5.47"
compile "org.rapidprom:Animation:6.5.50"
compile "org.rapidprom:ApacheUtils:6.7.88"
compile "org.rapidprom:BasicUtils:6.7.104"
compile "org.rapidprom:BPMN:6.5.56"
compile "org.rapidprom:BPMNConversions:6.5.48"
compile "org.rapidprom:CPNet:6.5.84"
compile "org.rapidprom:DataAwareReplayer:6.7.563"
compile "org.rapidprom:DataPetriNets:6.5.291"
compile "org.rapidprom:DottedChart:6.5.17"
compile "org.rapidprom:EvolutionaryTreeMiner:6.7.154"
compile "org.rapidprom:EventStream:6.5.72"
compile "org.rapidprom:FeaturePrediction:6.5.61"
compile "org.rapidprom:Fuzzy:6.5.33"
compile "org.rapidprom:GraphViz:6.7.185"
compile "org.rapidprom:GuideTreeMiner:6.5.18"
compile "org.rapidprom:HeuristicsMiner:6.5.49"
compile "org.rapidprom:HybridILPMiner:6.7.116"
compile "org.rapidprom:InductiveMiner:6.7.297"
compile "org.rapidprom:InductiveVisualMiner:6.7.413"
compile "org.rapidprom:Log:6.7.293"
compile "org.rapidprom:LogDialog:6.5.42"
compile "org.rapidprom:LogProjection:6.5.38"
compile "org.rapidprom:ModelRepair:6.5.12"
compile "org.rapidprom:Murata:6.5.54"
compile "org.rapidprom:PetriNets:6.7.95"
compile "org.rapidprom:PNetAlignmentAnalysis:6.5.35"
compile "org.rapidprom:PNAnalysis:6.7.122"
compile "org.rapidprom:PNetReplayer:6.7.99"
compile "org.rapidprom:PTConversions:6.5.3"
compile "org.rapidprom:PomPomView:6.5.36"
compile "org.rapidprom:SocialNetwork:6.5.35"
compile "org.rapidprom:StreamAlphaMiner:6.5.15"
compile "org.rapidprom:StreamAnalysis:6.5.38"
compile "org.rapidprom:StreamInductiveMiner:6.5.42"
compile "org.rapidprom:TransitionSystems:6.7.71"
compile "org.rapidprom:TSPetriNet:6.5.35"
compile "org.rapidprom:Uma:6.5.46"
compile "org.rapidprom:Woflan:6.7.59"
compile "org.rapidprom:XESLite:6.7.217"
compile "org.rapidprom:Weka:6.7.3"
}
To deploy to Maven, use the maven plugin.
apply plugin: 'maven'
group = 'com.company'
version = '1.0.0.6'
// To build and push development snapshots, add a suffix to the name
// version = '1.0.0.6-SNAPSHOT'
artifacts {
archives jar
}
uploadArchives {
repositories {
mavenDeployer {
snapshotRepository(url: 'https://maven.repo/bla') {
authentication(userName: snapshotUser, password: snapshotPassword)
}
repository(url: 'https://maven.repo/bla') {
authentication(userName: releaseUser, password: releasePassword);
}
}
}
}
You can both install to a remote repository by running the uploadArchives task, (example above is https://maven.repo/bla), or install to ~/.m2/repository which is maven local using the install task.
gradle install uploadArchives
If you choose to install to maven local, you can add a dependency on maven local to other gradle projects by using dependencies { mavenLocal() }, or including it in your pom.xml
<settings <!-- bla --> >
<localRepository>${user.home}/.m2/repository</localRepository>
</settings>
I am getting the following error while spring boot jar in CI environment
java -jar application.jar
no main manifest attribute, in application.jar
The weird thing is, it does not give the issue in my local or jenkins slave. It starts all right.
It faces issue when I upload the jar to Nexus artifactory and download it on my CI environment.
Building jar using
gradle clean build -x test
My gradle.build file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.2.4'
classpath 'org.ajoberstar:gradle-jacoco:0.1.0'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
credentials {
username "hello"
password "world"
}
url "Nexus URL"
}
}
apply plugin: 'maven-publish'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: "org.sonarqube"
apply plugin: 'jacoco'
group = 'com.company.pod'
/* Determining version from jenkins pipeline, otherwise is set to 1.0.0-SNAPSHOT */
version = new ProjectVersion(1, 0, System.env.SOURCE_BUILD_NUMBER, System.env.RELEASE_TYPE)
println(version)
class ProjectVersion {
Integer major
Integer minor
String build
String releaseType
ProjectVersion(Integer major, Integer minor, String build, String releaseType) {
this.major = major
this.minor = minor
this.build = build
this.releaseType = releaseType
}
#Override
String toString() {
String fullVersion = "$major.$minor"
if(build) {
fullVersion += ".$build"
}
else{
fullVersion += ".0"
}
if(releaseType) {
fullVersion += "-RELEASE"
}
else{
fullVersion += "-SNAPSHOT"
}
fullVersion
}
}
/*Sonarqube linting of your repository.*/
sonarqube {
properties {
property "sonar.language", "java"
}
}
/* Please don't comment out the part below
To run the same on your laptops/prod boxes/CUAT boxes, just edit the gradle.properties file.
(It will be present in the home directory of the user you are using to run gradle with.`sudo` means root user and likewise)
Enter the following lines(and yes, it will run without values, thank you gradle!)
nexusUrl=
nexusRelease=
nexusSnapshot=
nexusUsername=
nexusPassword=
*/
uploadArchives {
repositories {
mavenDeployer {
repository(url: nexusUrl+"/"+nexusRelease+"/") {
authentication(userName: nexusUsername, password: nexusPassword)
}
snapshotRepository(url: nexusUrl+"/"+nexusSnapshot+"/"){
authentication(userName: nexusUsername, password: nexusPassword)
uniqueVersion = false
}
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.company.something'/*This is different from group variable before*/
artifactId 'something'
version '2.0.0'
from components.java
}
}
}
/*
publishing {
repositories {
maven {
url "~/.m2/repository/"
}
}
}
*/
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
distributionUrl = "https://services.gradle.org/distributions/gradle-$GradleVersion-all.zip"
}
dependencies {
compile('org.projectlombok:lombok:1.16.6')
compile("com.company.commons:company-app:0.0.1-RELEASE")
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile("com.squareup.retrofit2:retrofit:2.0.1")
compile("com.squareup.retrofit2:converter-jackson:2.0.1")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
compile("com.getsentry.raven:raven-logback:7.2.2")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("com.h2database:h2")
testCompile("junit:junit")
// testCompile("org.springframework.boot:spring-boot-starter-test")
// testCompile group: 'org.hibernate', name: 'hibernate-validator', version: '4.2.0.Final'
}
Articles consulted with no vain
1. Gradle- no main manifest attribute
2. http://www.vogella.com/tutorials/Gradle/article.html#specifying-the-java-version-in-your-build-file
3. Can't execute jar- file: "no main manifest attribute"
The default packaged jar file does not contain MANIFEST file.
I don't know how to configure in Gradle, but in Maven when I added plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>vn.dung.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
And it works for me.
You could change that Maven plugin config to Gradle.
i had to run gradle bootRepackage after building the jar and git a jar that I could execute!
It worked with
gradle upload -x jar
In build.gradle, I noticed boot repackaging was disabled so I enabled it :
bootRepackage {
enabled = true
}
Hi I had exactly same problem, and I found the answer in:
Spring Boot Upload BootRepackage Executable Jar
I used the solution 2
publish {
dependsOn assemble
}
I was looking up how to get the application name(artifact id) and version from maven pom or manifest when I came across this question Get Maven artifact version at runtime.
The above works for me when I package the project but I can't seem to get anything to work when I try to run the program using eclipse. I tried using the .properties method when building since I assumed that is not package dependent but I am still not getting a result. If anyone has an idea or solution to this problem it would be greatly appreciated.
My last attempt is below. This uses the manifest when packaged(which works) and trying to get the .properties file when running in eclipse.
String appVersion = getClass().getPackage().getImplementationVersion();
if(appVersion == null || "".equals(appVersion)) {
appVersion = Glob.getString(appVersion);
if(appVersion == null || "".equals(appVersion)) {
System.exit(0);
}
}
Create a property file
src/main/resources/project.properties
with the below content
version=${project.version}
artifactId=${project.artifactId}
Now turn on maven resource filtering
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
so that this file is processed into
target/classes/project.properties
with some content similar to this
version=1.5
artifactId=my-artifact
Now you can read this property file to get what you want and this should work every time.
final Properties properties = new Properties();
properties.load(this.getClassLoader().getResourceAsStream("project.properties"));
System.out.println(properties.getProperty("version"));
System.out.println(properties.getProperty("artifactId"));
An easy solution with maven 4 is now to add a VersionUtil static method in your package:
package my.domain.package;
public class VersionUtil {
public static String getApplicationVersion(){
String version = VersionUtil.class.getPackage().getImplementationVersion();
return (version == null)? "unable to reach": version;
}
}
The thing is you need this ´mave-war-plugin´ in the project's pom, saying you want to add addDefaultImplementationEntries:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
...
Then call the VersionUtil.getApplicationVersion() from some place in your code.
How do I get the Maven version of my project programatically?
In other words:
static public String getVersion()
{
...what goes here?...
}
For example, if my project would generate the jar CalculatorApp-1.2.3.jar, I want getVersion() to return 1.2.3.
Create file version.prop in src/main/resources with the following contents:
version=${project.version}
Add the following to your project's pom:
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/version.prop</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/version.prop</exclude>
</excludes>
</resource>
</resources>
...
</build>
Add the following method:
public String getVersion()
{
String path = "/version.prop";
InputStream stream = getClass().class.getResourceAsStream(path);
if (stream == null)
return "UNKNOWN";
Properties props = new Properties();
try {
props.load(stream);
stream.close();
return (String) props.get("version");
} catch (IOException e) {
return "UNKNOWN";
}
}
p.s. Found most of this solution here: http://blog.nigelsim.org/2011/08/31/programmatically-getting-the-maven-version-of-your-project/#comment-124
For jar files, you have the MANIFEST.MF as the default place to put the Implementation-Version there. Maven supports building the jar file like this.
See also
How do I add an Implementation-Version value to a jar manifest using Maven?