Module files needed to run an application in gradle - java

I have an application in gradle divided into several modules https://zapodaj.net/745369ca57478.png.html. I want to throw him onto GitHub now. I'm not sure which files are needed. I currently have added in the gitignore file
# gradle config
.gradle/
# Intellij Idea project files
.idea/
out/
*.iml
# project binaries
build/`
In each .gitigore file I have typed the same thing. But in modules, I do not need files, perhaps
gradlew
gradlew.bat
Can I remove these two files from the modules and only stay out of the modules only? It seems to me that these two files are only needed outside the modules.

Yes, if you already include all the module in setting.gradle, then you don't need those 2 file and the gradle folder in each module
include ":core", ":common", ":web"

Related

What files in a Maven project should be committed to git?

I want to know what files in a Maven project should be committed to git.
Am I suppose to perform a mvn clean before committing, or do I add certain files to the .gitignore file?
Personally I use Maven gitignore and Java gitignore for a Maven project. You might need to adjust it with the languages used in your Maven project.
https://github.com/github/gitignore/blob/master/Maven.gitignore
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
https://github.com/github/gitignore/blob/master/Java.gitignore
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
Is it good practice to perform mvn clean before committing, or do I add certain files to the .gitignore file?
Add rules to your .gitignore file first, which makes Git ignores the undesired files correctly. Understanding Maven standard directory layout will also help you better determine which are the undesired directories.
Is it good practice to perform mvn clean before committing, or do I
add certain files to the .gitignore file?
Executingmvn clean before committing is not practical at all. Developers can forget that and besides they should rebuild their projects at each commit.
The correct way is using .gitignore to specify files to ignored in the tracking. Just commit it and push into the remote branch and all developers could work with the same rules.
I want to know what files in a Maven project should be committed to
git.
You want to commit/push files that you want to version/track.
But it is very broad. You cannot have rules just for Maven. Maven have some specificities (target folder for example that you want to ignore) but you would have probably more things to ignore.
You want to generally commit/push the source code and application configuration files such as pom.xml or any configuration files used in your build but you can also add any other kind of files. For example committing a changelog or even a word document (more rare but possible) may also be valid.
Generally what you don't want to commit are files that :
depends on the developer machine (IDE, custom files)
created by a build operation (target folder in Maven but you could also have other folders according to your pom configuration)
temporary files using during the build, the application execution or still the release operations.
archives
Check this:
https://www.gitignore.io/api/maven
# Created by https://www.toptal.com/developers/gitignore/api/maven
# Edit at https://www.toptal.com/developers/gitignore?templates=maven
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
# End of https://www.toptal.com/developers/gitignore/api/maven
In general you should ignore all targets and metadata. If you ignore targets, mvn clean is not required before pushing.
I had a Maven project in VSCodium and had to decide whether to commit the .project file or not. That should be linked to in this Q/A since it happens with other IDE:s as well that have Maven extensions.
This is 2010, only for Eclipse:
.classpath and .project - check into version control or not?
which says overall that it should be committed. I guess the discussion is timeless. It is a Maven generated file, but it should still be in the repository, and even more, if the repository is at work with the same setup and tools by the team.
Other questions:
Should I keep my project files under version control? [closed]
Java project: should .classpath .project file be committed into repository? [duplicate]
The same for the .classpath. Even if it is made by Maven, it should be in the repo.
I am a beginner at Maven and only guess this. I cannot understand why this was not in this Q/A up to now. The accepted answer lists the ignored files, but from reading that, I was not fully sure what to do with these meta files from Maven. And there is even one answer that lists the two files as files that are to be ignored in this Q/A here. Which, as far as I can see from a repository I took over, and guessing from the accepted answer, is wrong: the two files belong to the version control.

SBT not adding unmanaged JARs

Hey I am trying to sbt compile a Scala project with 2 external .jar libraries as dependencies. I've added them in the /lib folder and I can see they are recognized by sbt when I run "show unmanagedClasspath" I see the 2 jars. However when I run "sbt assembly", sbt tries to resolve dependencies and fails when it can't download the libraries that are already there.
You don't need to add the jars that you've in the \lib directory again in libraryDependencies. libraryDependencies is part of your managedClasspath and everything in lib directory is part of your unmanagedClasspath, both together forms your dependencyClasspath.
You can see this by typing this on sbt prompt and checking the dependencies section:
inspect externalDependencyClasspath
In this case 'external' just means dependencies that are external to the project (ie not internal project dependencies)

How to build Java project using IntlliJ IDE instead of via shell?

I cloned a GitHub repo onto my disk an successfully built the project by:
ant clean-all resolve create-dot-classpath
within the projects root directory.
I assume this should also be possible from IntelliJ IDE but that fails by doing nothing at all - it simply states "All files are up-to-date" ... what I do is:
"Make module 'pentaho-kettle'"
"Compile module 'pentaho-kettle'"
I could use a hint where to look for a solution or what configuration is most likely missing.
As the project is a multi module project based on Ant and Ivy, you have to
import the project from sources
configure modules (like core, ui, the plugins, …) with the right directories for main and test sources and resources (they seem to overlap with java sources in that project)
setup the class path using an Ivy plugin (I recommend IvyIDEA), use the context menu on the ivy.xml file
and have luck to build. It will be some try and error!
You may also have a try importing from Eclipse as those .project and .classpath files are checked in. But than you also have to check the module directories, the import is more a partial guess and I worry that IntelliJ will not get any information about Ivy from the Eclipse setup.

adding android project to git

Which are the files that I have to ignore when adding a project to git?
Should I add the .classpath file?
What is the purpose of .classpath?
Im using eclipse and pushing to a Jenkins server
Typical gitignore file for android would include this:
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
From Gitignore on github
While creating a project in Eclipse, by default it creates a .classpath file in the project directory. That file will be used for storing file names and other dependent files needed in the classpath to compile and execute the project successfully. Normally this file will be updated automatically when ever you update the project libraries etc.
You should add it to git in my opinion. See this thread for more:
.classpath and .project - check into version control or not?

How to build a runnable jar with internal jar files that have internal jar files?

I have a huge project (Application) with another project inside it (Core). Application has a big set of libraries inside as does Core. I'm using Eclipse and so I'm using the Export Runnable Jar option to create Application.jar but when I run it part of the code uses the Core which has a dependency on an image library within that. When I look inside the runnable jar file all the libraries for the Application project are there but when I look inside the Core project jar file the libraries aren't there. To give you an idea of what I mean the structure I'm expecting looks like this:
Application
- Core.jar
+ ImageLibrary.jar
+ OtherLibraries.jar
:
+ OtherLibraries.jar
:
I'm using Maven to build the projects individually. But I'm not really an expert with Maven as I've only being using it for a short time.
Is it possible to build Application so that Core also has its libraries with it?
Thanks in advance,
Alexei Blue.
In your Maven build for Application, is Core not specified as a dependency? If so, it should be included with all its dependencies. You should probably check whether the dependencies themselves have the correct scope in Maven to be included.
Okay so I figured this one out in the end. When I was using Maven to build the project it was doing so and then not updating the build path in eclipse. So I in the core directory I ran:
# mvn clean install
# mvn eclipse:eclipse
As the image library was an addition to the Core dependencies I had to ensure that the build path for eclipse was set otherwise eclipse won't pick up the changes. The eclipse:eclipse command did this for me but I think it only works in projects that are one module, however it reads any dependencies from your pom file and ensures your project can see and access them.
And then in the App directory I re built the project:
# mvn clean install
Then from within eclipse I exported the App project as a Runnable Jar which worked fine.
Hope this helps anyone having the same problem.
Cheers,
Alexei Blue.

Categories