I am new to the C# and i see that in xunit project i can add nuget packages. My question is around its use by different team members when code is pushed in git hub/azure.
I can add nuger packages like specflow, dependecy injection and work locally but how can i ensure that when i push code in github or azure next team member who clones repo can also use or see the packages added? is there any mechanism in C# like in java Maven we have pom.xml or gradle.build file or it happens automatically in C#
The nuget packages are added to your .csproj file (before that there was a dedicated packages file). When someone pulls your changes and builds the solution, those packages will be downloaded automatically.
See here: https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
Here is a good explanation, how nuget packages are working in Visual Studio.
After cloning/pulling from Github, a "Package Restore" might be necessary:
https://fossa.com/blog/dependency-management-visual-studio-nuget-beyond/#Restoring
Related
The case is quite simple, but I still can't solve it:
INFO: All 'projects' I am talking about are Maven projects.
I have certain Java project that I am working on right now. Recently, I have written a lot of general-purpose code in this project. I also have an 'utils' project with some Java utils in it, so I decided to move the general-purpose code from my main project (let's call it 'A') to the utils project. This would be practical because:
I have less clutter in A
I can reuse the code in other projects without bringing the unrelated content of 'A' in scope.
The problem is that utils is, of course, an utility project, a library if you want. And it does not have a main class. When I try to install (mvn install) it, no sources are included because there is no proper entry point.
So, after trying a lot of things, I have the concern that I am approaching this problem completely wrong and that's why I came here. I do not have any experience with Maven except the simple use case (e.g. including external libraries from Maven Central). Therefore my question is:
Which steps are required to make my utils library available in project 'A'?
I am not aiming to install my project on Maven Central or any other remote repository. I just want it available in my local mvnrepo. I am aware that this means that I'll have to clone my utils project and install it everywhere where I try to use project 'A'.
EDIT 1: I am using Java 11 (openjdk11), Maven 3.6.0, IntelliJ IDEA Ultimate with Maven Helper plugin and also GitHub in order to make my projects available anywhere.
Also, I have just checked that project 'A' correctly includes the jar from the utils project and actually adds it to the classpath (but the jar is empty). So, the problem really seems to be in the utils project.
A maven install would place your compiled code in the local maven repository (.m2/repository).
Sources are packaged by the source plugin.
mvn source:jar
I am sorry i don't know maven good enough for the complex environment i am currently working in (1k+ applications, most of them are Java EE). I still give it a try to describe what i want to archive:
0.) There is a company framework that abstracts the Java EE World a bit and is used in all the Java EE components
1.) I checked out the maven project of the Java EE component i am working with
during the build it downloads the dependencys of other components out of the companys repository and stores it inside my local repo for compilation. So i can see the jar-files of the companys framework inside my local repo.
2.) I now want to change some of the frameworks functionality for a local test so i checked out their sources from another SVN repository. I made the changes and build that framework component with maven "clean install".
3.) I rebuild the component i am working with as well.
Inside eclipse i can now click on one of a frameworks classes method and it opens the according source. But this only happens because the local repo is meant to contain source-jars for any dependency as well. So in my editor i can see this source is from the jar of the framework in my local repo and i cant change anything.
Could someone please give me a hint how i can archive the following:
I can make changes to the framework (and build the frameworks jars with "clean install")
I can build my component and it uses the above compiled framework jars rather than the "old" ones from the local repo.
I will right now start to read the entire maven documentation and each and every section (i try to understand that dependency management since 1 year and still don't get it) but i would really appreciate if you could help me out a bit here.
I don't know how Eclipse manages maven dependencies, but
In IntelliJ IDEA this is simple - if maven dependency is in project then IDEA uses it instead of dependency from local repo.
So if u want to edit framework source code and use this changes immidiately - i think that framework should be in your Eclipse Workspace. And your module in Eclipse should reference framework artifacts directly - not over Maven dependency mechanism.
I think that this is a Eclipse Maven plugin responsibility. Do u have any installed Maven plugin for Eclipse? (M2Eclipse for example)
I'm using m2e (1.0.100), Eclipse (Indigo SR1) and hibernate-jpamodelgen (1.1.1.Final).
I want to have hibernate generate the Canonical metamodel from my entities when I compile the projects.
I was able to do this previously when I was working on a non-maven project and I followed the numerous tutorials there are on how to configure the eclipse project to use this jar.
However, to the best of my understanding, when using m2e it is best (mandatory?) to let it do the eclipse configuration for you and so I'm not sure how this should be done.
This hibernate tutorial explains how to use the generator with maven and eclipse but separately.
I think what I'm missing is gluing my pom, which was generated as a simple no archetype pom, and my eclipse project configuration so that they enable me to do some JPA magic.
BTW, following the above tutorial for maven caused my maven-generated jars to contain the _ classes but these are not seen by eclipse since they are only in the jars and not in the actual projects.
Thanks in advance
I've asked the same question on the m2e-users mailing list and got the following answer (link for those wanting the full thread):
Basically one should manually configure (for example using the above mentioned hibernate tutorial) eclipse to use the generator and configure the same directory maven uses (for me it was target/generated-sources/annotations) as the output directory.
According to the committers of m2e, the project currently does not change these eclipse files and so this won't be overriden from them.
The problem I did face was that this information is lost (and so the manual change is needed again) when using GIT and switching between branches as I don't want to commit any eclipse related files to the SCM.
Currently this is an acceptable solution and I hope m2e will be able to add this missing feature.
Update
The information that is lost, at least according to my experience, is the definition of the target/generated-sources/annotations folder as a source folder. Just as an FYI.
I am converting a large Java project to use maven. I have a LOT of inter dependencies to work out, but I would like to get it off the ground with maven before I do the real cleanup work. I have broken it up into a few modules plus one giant module; let's call that module monolith.
Monolith has regular Java classes and some gwt classes (with interdependencies). I separated the two parts to have a directory structure like this:
./src/main/java/...
./src/client/gwt/...
So, I can easily get this to compile in eclipse with m2eclipse, but then I can't seem to find how to get it to compile with maven. I saw that the pom file has a build section where you can specify an alternate source and target, but I think it is not a repeatable attribute in the pom:
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
</build>
In eclipse, I can adjust the project's .classpath file (in the project properties) to add additional source files (and output dirs) to accomplish what I am looking to do.
Is there any way to do this, or do I need to work out the dependencies first, and separate into separate modules?
If you go against the grain with maven it will be an uphill battle all the way.
Maven doesn't lean towards multiple main source directories, they would do better in maven environment as separate modules.
I've looked at a number of maven gwt projects and archetypes, and none of them seem to take the approach you've suggested.
Have a look at the source structure used by Hupa, also see the archetypes from the Ham and Eggs blog
http://hamandeggs.wordpress.com/2010/01/26/how-to-gae-eclipse-maven/
http://hamandeggs.wordpress.com/2010/07/25/gae-eclipse-maven-update-for-helios/
These also cater for App Engine.
If you really need to separate your java server source from your gwt client source, then monolith needs to be split into more modules.
It is quite common to see gwt projects with a package structure as follows:
com.company.project
.client
.server
.shared
And then specify the source paths in your gwt.xml to include client and shared
What you have is called a maven multi-module project. Take a look at this tutorial on the maven book.
So, I can easily get this to compile
in eclipse with m2eclipse, but then I
can't seem to find how to get it to
compile with maven.
-- I am not sure what you meant by this. M2Eclipse plugin is using maven to build your modules. Perhaps you can clarify this section. Hope the tutorial link helps you.
try to follow this tutorial http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html
main idea- start from creation of empty project from maven mvn archetype:create and then put you sources to created by maven structure...
also i can strongly recommend to check your dependency tree and effective pom with eclipse plugin tool when you perform this task (for avoid duplicate in dep. & other bad things)
In Java if you package the source code (.java) files into the jar along with classes (.class) most IDE's like eclipse will show the javadoc comments for code completion.
IIRC there are few open-source projects that do this like JMock.
Lets say I have cleanly separated my API code from implementation code so that I have something like myproject-api.jar and myproject-impl.jar is there any reason why I should not put the source code in my myproject-api.jar ?
Because of Performance? Size?
Why don't other projects do this?
EDIT: Other than the Maven download problem will it hurt anything to put my sources into the classes jar to support as many developers as possible (maven or not)?
Generally because of distribution reason:
if you keep separate binaries and sources, you can download only what you need.
For instance:
myproject-api.jar and myproject-impl.jar
myproject-api-src.jar and myproject-impl-src.jar
myproject-api-docs.zip and myproject-impl-docs.zip
Now, m2eclipse - Maven for Eclipse can download sources automatically as well
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
Now, it can also generate the right pom to prevent distribution of the source or javadoc jar when anyone declare a dependency on your jar.
The OP comments:
also can't imagine download size being an issue (i mean it is 2010 a couple 100k should not be a problem).
Well actually it (i.e. "the size) is a problem.
Maven suffers already from the "downloading half the internet on first build" syndrome.
If that downloads also sources and/or javadocs, that begins to be really tiresome.
Plus, the "distribution" aspect includes the deployment: in a webapp server, there is no real advantage to deploy a jar with sources in it.
Finally, if you really need to associate sources with binaries, this SO question on Maven could help.
Using maven, attach the sources automatically like this:
http://maven.apache.org/plugins/maven-source-plugin/usage.html
and the javadocs like this:
http://maven.apache.org/plugins/maven-javadoc-plugin/jar-mojo.html
That way they will automatically be picked up by
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
or by m2eclipse